diff --git a/.clang-format b/.clang-format index 8a110c1cec8..f89761751ea 100755 --- a/.clang-format +++ b/.clang-format @@ -1,20 +1,37 @@ BasedOnStyle: LLVM -Language: Cpp -Standard: Cpp11 +Standard: c++17 IndentWidth: 4 ColumnLimit: 120 +AllowShortIfStatementsOnASingleLine: false AlwaysBreakTemplateDeclarations: true AlwaysBreakAfterReturnType: All -PointerAlignment: Left -AllowShortIfStatementsOnASingleLine: false -BreakBeforeBraces: Allman - -# Disable formatting options which may break tests. -SortIncludes: false -ReflowComments: false +BraceWrapping: + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterExternBlock: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyNamespace: true + SplitEmptyRecord: true +BreakBeforeBraces: Custom # Indent preprocessor directives IndentPPDirectives: AfterHash + +PointerAlignment: Left +# Disable formatting options which may break tests. +ReflowComments: false +SortIncludes: false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6836cb1a2ce..cd4db9438c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,17 +17,23 @@ env: jobs: clang-format: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + - uses: actions/setup-python@v3 + with: + python-version: '3.x' - name: Get clang-format - run: sudo apt-get install -yqq clang-format-6.0 + run: sudo apt-get install -yqq clang-format - name: Applying clang-format for changed files run: | - FILES=$(git diff --diff-filter=d --name-only ${{ github.event.pull_request.base.sha }} | grep ^include | grep -v nanorange\.hpp\$ || true) - echo $FILES | xargs -n1 -t -r clang-format-6.0 --style=file -i + MERGE_BASE=${{ github.event.pull_request.base.sha }} + FILES=$(git diff --diff-filter=d --name-only $MERGE_BASE | grep ^include | grep -v nanorange\.hpp\$ || true) + CLANG_FORMAT_DIFF_PATH=$(which clang-format-diff) + echo $FILES | xargs -n1 -t -r git diff -U0 --no-color --relative $MERGE_BASE | python3 $CLANG_FORMAT_DIFF_PATH -i -p1 -style file - name: Creating diff run: git diff > clang-format.diff - name: Checking if diff is empty