-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces clang-format to enforce a consistent code style for Stockfish. Having a documented and consistent style across the code will make contributing easier for new developers, and will make larger changes to the codebase easier to make. To facilitate formatting, this PR includes a Makefile target (`make format`) to format the code, this requires clang-format (version 17 currently) to be installed locally. Installing clang-format is straightforward on most OS and distros (e.g. with https://apt.llvm.org/, brew install clang-format, etc), as this is part of quite commonly used suite of tools and compilers (llvm / clang). Additionally, a CI action is present that will verify if the code requires formatting, and comment on the PR as needed. Initially, correct formatting is not required, it will be done by maintainers as part of the merge or in later commits, but obviously this is encouraged. fixes #3608 closes #4790 Co-Authored-By: Joost VandeVondele <[email protected]>
- Loading branch information
Showing
49 changed files
with
6,963 additions
and
6,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
AccessModifierOffset: -1 | ||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveAssignments: Consecutive | ||
AlignConsecutiveDeclarations: Consecutive | ||
AlignEscapedNewlines: DontAlign | ||
AlignOperands: AlignAfterOperator | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortEnumsOnASingleLine: false | ||
AllowShortIfStatementsOnASingleLine: false | ||
AlwaysBreakTemplateDeclarations: Yes | ||
BasedOnStyle: WebKit | ||
BitFieldColonSpacing: After | ||
BinPackParameters: false | ||
BreakBeforeBinaryOperators: NonAssignment | ||
BreakBeforeBraces: Custom | ||
BraceWrapping: | ||
AfterFunction: false | ||
AfterClass: false | ||
AfterControlStatement: true | ||
BeforeElse: true | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializers: AfterColon | ||
BreakStringLiterals: false | ||
ColumnLimit: 100 | ||
ContinuationIndentWidth: 2 | ||
Cpp11BracedListStyle: true | ||
IndentGotoLabels: false | ||
IndentPPDirectives: BeforeHash | ||
IndentWidth: 4 | ||
MaxEmptyLinesToKeep: 2 | ||
NamespaceIndentation: None | ||
PackConstructorInitializers: Never | ||
ReflowComments: false | ||
SortIncludes: false | ||
SortUsingDeclarations: false | ||
SpaceAfterCStyleCast: true | ||
SpaceAfterTemplateKeyword: false | ||
SpaceBeforeCaseColon: true | ||
SpaceBeforeCpp11BracedList: false | ||
SpaceBeforeInheritanceColon: false | ||
SpaceInEmptyBlock: false | ||
SpacesBeforeTrailingComments: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This workflow will run clang-format and comment on the PR. | ||
# Because of security reasons, it is crucial that this workflow | ||
# executes no shell script nor runs make. | ||
# Read this before editing: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | ||
|
||
name: Stockfish | ||
on: | ||
pull_request_target: | ||
branches: | ||
- 'master' | ||
paths: | ||
- '**.cpp' | ||
- '**.h' | ||
jobs: | ||
Stockfish: | ||
name: clang-format check | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Run clang-format style check | ||
uses: jidicula/clang-format-action@f62da5e3d3a2d88ff364771d9d938773a618ab5e | ||
id: clang-format | ||
continue-on-error: true | ||
with: | ||
clang-format-version: '17' | ||
exclude-regex: 'incbin' | ||
|
||
- name: Comment on PR | ||
if: steps.clang-format.outcome == 'failure' | ||
uses: thollander/actions-comment-pull-request@1d3973dc4b8e1399c0620d3f2b1aa5e795465308 | ||
with: | ||
message: | | ||
clang-format 17 needs to be run on this PR. | ||
If you do not have clang-format installed, the maintainer will run it when merging. | ||
For the exact version please see https://packages.ubuntu.com/mantic/clang-format-17. | ||
_(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ | ||
comment_tag: execution | ||
|
||
- name: Comment on PR | ||
if: steps.clang-format.outcome != 'failure' | ||
uses: thollander/actions-comment-pull-request@1d3973dc4b8e1399c0620d3f2b1aa5e795465308 | ||
with: | ||
message: | | ||
_(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ | ||
create_if_not_exists: false | ||
comment_tag: execution | ||
mode: delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.