Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and enforce formatting for C/C++ (#1474) #1496

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/stylecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,51 @@ jobs:
git diff --color=always --minimal
exit 1
fi

clang-format:
runs-on: ubuntu-latest

env:
LLVM_VERSION: 18

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install clang-format
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh ${{ env.LLVM_VERSION }}
rm -rf llvm.sh
sudo apt install clang-format-${{ env.LLVM_VERSION }}
git config --global clangFormat.binary "clang-format-${{ env.LLVM_VERSION }}"

- name: Fix formatting (pull_request)
if: ${{ github.event_name == 'pull_request' }}
continue-on-error: true
run: git clang-format-${{ env.LLVM_VERSION }} ${{ github.event.pull_request.base.sha }} --verbose

- name: Fix formatting (push)
if: ${{ github.event_name == 'push' }}
continue-on-error: true
run: git clang-format-${{ env.LLVM_VERSION }} HEAD~1 --verbose

- name: Ignore changes in external code
run: |
git restore ./Externals
git restore ./res
git restore ./sdk
git restore ./src/utils/mp_gpprof_server/libraries

- name: Report result
run: |
if [ -z "$(git status -s)" ]; then
echo Everything seems to be in order
else
echo Formatting problems found!
git diff --color=always --minimal
exit 1
fi
38 changes: 32 additions & 6 deletions src/.clang-format
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
Language: Cpp
Standard: c++17

AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
Expand All @@ -9,8 +11,10 @@ AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
Expand All @@ -19,6 +23,7 @@ AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
Expand All @@ -30,18 +35,26 @@ BraceWrapping:
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyNamespace: false
SplitEmptyRecord: false
BreakAfterAttributes: Never
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
ColumnLimit: 120
CommentPragmas: '^ (IWYU pragma:|NOLINT)'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
FixNamespaceComments: true
ForEachMacros: [ ]
IncludeCategories:
- Regex: 'stdafx.h'
Expand All @@ -51,8 +64,11 @@ IncludeCategories:
- Regex: '^"'
Priority: 2
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
Expand All @@ -68,19 +84,29 @@ PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
QualifierAlignment: Left
ReferenceAlignment: Left
ReflowComments: true
SortIncludes: false
RemoveBracesLLVM: true
RemoveParentheses: Leave
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Before
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInParens: Never
SpacesInSquareBrackets: false
Standard: c++11
TabWidth: 4
UseTab: Never
...
Loading