From be71ec28c9b342e96a892c108fede4074d34969a Mon Sep 17 00:00:00 2001 From: Ariya Hidayat Date: Tue, 7 Jan 2020 16:43:05 -0800 Subject: [PATCH] CI to check for coding style (#15404) --- CONTRIBUTING.md | 2 ++ azure-pipelines.yml | 11 +++++++++++ tools/check-style.bat | 20 -------------------- tools/format-code.sh | 4 ++++ 4 files changed, 17 insertions(+), 20 deletions(-) delete mode 100644 tools/check-style.bat create mode 100755 tools/format-code.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7fd2f83b85..04d3ac50ca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,6 +37,8 @@ For your proposed change, you need to have: * **an issue** (in the issue tracker) which describe your bug or feature * **a feature branch** in your git fork +Make sure your code change follows the style guide. To format your code, run `./tools/format-code.sh`. + ### Refer the Issue The commit message needs to link to the issue. This cross-reference is [very important](http://ariya.ofilabs.com/2012/01/small-scale-software-craftsmanship.html) for the following reasons. diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 59d4bf0d4e..e5196045a6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,5 +1,16 @@ jobs: +- job: 'CodeQuality' + pool: + vmImage: 'macOS 10.13' + steps: + - script: brew install clang-format && clang-format --version + displayName: 'Install clang-format' + - script: bash ./tools/format-code.sh + displayName: 'Run code formatter' + - script: git diff --quiet HEAD + displayName: 'Check if the styling guide is followed' + - job: 'amd64_linux_gcc' pool: vmImage: 'ubuntu-18.04' diff --git a/tools/check-style.bat b/tools/check-style.bat deleted file mode 100644 index e412b30e8c..0000000000 --- a/tools/check-style.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -set ROOT_DIR=%CD% - -set CONFIG= -set CONFIG=%CONFIG% --indent=spaces=4 -set CONFIG=%CONFIG% --style=otbs -set CONFIG=%CONFIG% --indent-labels -set CONFIG=%CONFIG% --pad-header -set CONFIG=%CONFIG% --pad-oper -set CONFIG=%CONFIG% --unpad-paren -set CONFIG=%CONFIG% --keep-one-line-blocks -set CONFIG=%CONFIG% --keep-one-line-statements -set CONFIG=%CONFIG% --convert-tabs -set CONFIG=%CONFIG% --indent-preprocessor -set CONFIG=%CONFIG% --align-pointer=type -set CONFIG=%CONFIG% --suffix=none - -call astyle %CONFIG% !ROOT_DIR!\..\src\*.cpp -call astyle %CONFIG% !ROOT_DIR!\..\src\*.h diff --git a/tools/format-code.sh b/tools/format-code.sh new file mode 100755 index 0000000000..b88c5a093e --- /dev/null +++ b/tools/format-code.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +cwd=$(pwd) +clang-format -i --style=WebKit $cwd/src/*.h $cwd/src/*.cpp