From 955c071593c410cfe559ba3f51f563af4bad1195 Mon Sep 17 00:00:00 2001 From: Kevin Wilfong Date: Mon, 17 Jun 2024 11:05:40 -0700 Subject: [PATCH] Update clang-format lint rules (#10181) 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: https://github.com/facebookincubator/velox/pull/10181 Reviewed By: kgpai Differential Revision: D58592253 Pulled By: kevinwilfong fbshipit-source-id: 4d159caff85ceac6ebc6d2831ebdededed97a4be --- .clang-format | 73 +++++++++++++++++++++++++++++++----------- scripts/check.py | 2 +- scripts/setup-check.sh | 4 +-- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/.clang-format b/.clang-format index eab4576fe09a..2211eaceb316 100644 --- a/.clang-format +++ b/.clang-format @@ -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: @@ -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 @@ -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 ... diff --git a/scripts/check.py b/scripts/check.py index 87512747db39..a0051c7bbdcd 100755 --- a/scripts/check.py +++ b/scripts/check.py @@ -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: diff --git a/scripts/setup-check.sh b/scripts/setup-check.sh index 56965c3eee66..ac255ffa1543 100644 --- a/scripts/setup-check.sh +++ b/scripts/setup-check.sh @@ -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