Skip to content

Commit

Permalink
Improve clang-format check to reduce false positives (#715)
Browse files Browse the repository at this point in the history
- Change the clang-format github runner to check only the git diff delta changed lines made by the current PR. 

- Update our clang format to the newest version, and updates the style file to a modern group of settings which results in a very similar result to the existing combination of version /settings.

- Change the clang-format github runner to compare the current branch head to the "merge base", or common ancestor with main head, removing divergent files since last rebase with main.

- Update github runner to newest version of ubuntu from 20.04.

Signed-off-by: Dan Hoeflinger <[email protected]>
  • Loading branch information
danhoeflinger authored Sep 13, 2023
1 parent d06ef9a commit 00153d5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
35 changes: 26 additions & 9 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 00153d5

Please sign in to comment.