Skip to content

Commit

Permalink
Update clang-format lint rules (facebookincubator#10181)
Browse files Browse the repository at this point in the history
Summary:
Now that we're on Ubuntu 24.04 we can use a more recent version of clang-format, and we can add rules that we run
within Meta but are missing in OS.  This should help to reduce back and forth between contributors and Meta employees
when importing their changes.

I also updated the script that does the lint checks to also apply the checks to renamed files, as those may have additional
changes besides just being renamed.

Pull Request resolved: facebookincubator#10181

Reviewed By: kgpai

Differential Revision: D58592253

Pulled By: kevinwilfong

fbshipit-source-id: 4d159caff85ceac6ebc6d2831ebdededed97a4be
  • Loading branch information
kevinwilfong authored and facebook-github-bot committed Jun 17, 2024
1 parent 5768570 commit 955c071
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
73 changes: 55 additions & 18 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
---
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: false
AlignEscapedNewlines: Left
AlignOperands: DontAlign
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
Expand All @@ -31,19 +37,27 @@ BraceWrapping:
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ FOR_EACH, FOR_EACH_R, FOR_EACH_RANGE, ]
DisableFormat: false
FixNamespaceComments: true
ForEachMacros:
- FOR_EACH
- FOR_EACH_R
- FOR_EACH_RANGE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
Expand All @@ -52,36 +66,59 @@ IncludeCategories:
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertNewlineAtEOF: true
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
SpaceBeforeSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseCRLF: false
UseTab: Never
...
2 changes: 1 addition & 1 deletion scripts/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def get_files(commit, path):

if commit != "":
status, stdout, stderr = util.run(
f"git diff --relative --name-only --diff-filter='ACM' {commit}"
f"git diff --relative --name-only --diff-filter='ACMR' {commit}"
)
filelist = stdout.splitlines()
else:
Expand Down
4 changes: 2 additions & 2 deletions scripts/setup-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ set -x

export DEBIAN_FRONTEND=noninteractive
apt update
apt install --no-install-recommends -y clang-format-14 python3-pip git make ssh
apt install --no-install-recommends -y clang-format-18 python3-pip git make ssh
pip3 install --break-system-packages cmake==3.28.3 cmake_format black regex
pip3 cache purge
apt purge --auto-remove -y python3-pip
update-alternatives --install /usr/bin/clang-format clang-format "$(command -v clang-format-14)" 14
update-alternatives --install /usr/bin/clang-format clang-format "$(command -v clang-format-18)" 18
apt clean

0 comments on commit 955c071

Please sign in to comment.