-
Notifications
You must be signed in to change notification settings - Fork 106
Add clang-format configuration #326
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| Language: Cpp | ||
| IndentWidth: 2 | ||
| UseTab: Never | ||
| ColumnLimit: 120 | ||
| SortIncludes: false | ||
| AccessModifierOffset: -2 | ||
| ReflowComments: false | ||
| ConstructorInitializerIndentWidth: 2 | ||
| ContinuationIndentWidth: 2 | ||
| AllowShortFunctionsOnASingleLine: Inline | ||
| BreakBeforeBraces: Custom | ||
| BraceWrapping: | ||
| AfterExternBlock: true | ||
| AfterClass: true | ||
| AfterFunction: true | ||
| AfterNamespace: false | ||
| AfterEnum: false | ||
| AfterCaseLabel: true | ||
| AfterControlStatement: MultiLine | ||
| AfterStruct: false | ||
| AfterUnion: false | ||
| BeforeLambdaBody: false | ||
| BeforeElse: false | ||
| BeforeCatch: false | ||
| BeforeWhile: false | ||
| IndentBraces: false | ||
| SplitEmptyFunction: true | ||
| SplitEmptyRecord: false | ||
| SplitEmptyNamespace: true | ||
| PPIndentWidth: 2 | ||
| FixNamespaceComments: false | ||
| IndentPPDirectives: BeforeHash | ||
| SpaceBeforeParens: Custom | ||
| SpaceBeforeParensOptions: | ||
| AfterControlStatements: true | ||
| AfterForeachMacros: true | ||
| AfterFunctionDefinitionName: false | ||
| AfterFunctionDeclarationName: false | ||
| AfterIfMacros: true | ||
| AfterOverloadedOperator: false | ||
| AfterRequiresInClause: false | ||
| AfterRequiresInExpression: false | ||
| BeforeNonEmptyParentheses: false | ||
| SpaceAfterCStyleCast: false | ||
| SpaceAfterLogicalNot: false | ||
| SpaceAfterTemplateKeyword: false | ||
| SpaceAroundPointerQualifiers: Default | ||
| SpaceBeforeAssignmentOperators: true | ||
| SpaceBeforeCaseColon: false | ||
| SpaceBeforeCpp11BracedList: true | ||
| SpaceBeforeCtorInitializerColon: true | ||
| SpaceBeforeInheritanceColon: true | ||
| SpaceBeforeRangeBasedForLoopColon: true | ||
| SpaceBeforeSquareBrackets: false | ||
| SpaceInEmptyBlock: false | ||
| SpaceInEmptyParentheses: false | ||
| SpacesBeforeTrailingComments: 1 | ||
| SpacesInAngles: Never | ||
| SpacesInConditionalStatement: false | ||
| SpacesInContainerLiterals: true | ||
| SpacesInCStyleCastParentheses: false | ||
| SpacesInLineCommentPrefix: | ||
| Minimum: 1 | ||
| Maximum: -1 | ||
| IndentCaseBlocks: false | ||
| IndentCaseLabels: false | ||
| AlignAfterOpenBracket: DontAlign | ||
| BreakConstructorInitializers: BeforeComma | ||
| AlwaysBreakTemplateDeclarations: true | ||
| NamespaceIndentation: None | ||
| AlignArrayOfStructures: None | ||
| AlignConsecutiveAssignments: | ||
| Enabled: false | ||
| AcrossEmptyLines: false | ||
| AcrossComments: false | ||
| AlignCompound: false | ||
| PadOperators: false | ||
| AlignConsecutiveBitFields: | ||
| Enabled: false | ||
| AcrossEmptyLines: false | ||
| AcrossComments: false | ||
| AlignCompound: false | ||
| PadOperators: false | ||
| AlignConsecutiveDeclarations: | ||
| Enabled: false | ||
| AcrossEmptyLines: false | ||
| AcrossComments: false | ||
| AlignCompound: false | ||
| PadOperators: false | ||
| AlignConsecutiveMacros: | ||
| Enabled: false | ||
| AcrossEmptyLines: true | ||
| AcrossComments: false | ||
| AlignCompound: false | ||
| PadOperators: false | ||
| AlignEscapedNewlines: DontAlign | ||
| AlignOperands: Align | ||
| AlignTrailingComments: true | ||
| AllowAllArgumentsOnNextLine: false | ||
| AllowAllParametersOfDeclarationOnNextLine: true | ||
| AllowShortBlocksOnASingleLine: Empty | ||
| AllowShortCaseLabelsOnASingleLine: false | ||
| AllowShortEnumsOnASingleLine: true | ||
| AllowShortIfStatementsOnASingleLine: Never | ||
| AllowShortLambdasOnASingleLine: All | ||
| AllowShortLoopsOnASingleLine: false | ||
| AlwaysBreakAfterDefinitionReturnType: None | ||
| AlwaysBreakAfterReturnType: None | ||
| AlwaysBreakBeforeMultilineStrings: false | ||
| BinPackArguments: true | ||
| BinPackParameters: true | ||
| BitFieldColonSpacing: After | ||
| BreakBeforeBinaryOperators: NonAssignment | ||
| BreakBeforeConceptDeclarations: Always | ||
| BreakBeforeTernaryOperators: true | ||
| BreakInheritanceList: BeforeColon | ||
| BreakStringLiterals: true | ||
| CompactNamespaces: false | ||
| Cpp11BracedListStyle: true | ||
| PointerAlignment: Left | ||
| QualifierAlignment: Leave | ||
| ReferenceAlignment: Pointer | ||
| DerivePointerAlignment: false | ||
| DisableFormat: false | ||
| EmptyLineAfterAccessModifier: Leave | ||
| MaxEmptyLinesToKeep: 1 | ||
| EmptyLineBeforeAccessModifier: LogicalBlock | ||
| ExperimentalAutoDetectBinPacking: false | ||
| ForEachMacros: | ||
| - foreach | ||
| - Q_FOREACH | ||
MinyazevR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| StatementAttributeLikeMacros: | ||
| - Q_EMIT | ||
| StatementMacros: | ||
| - Q_UNUSED | ||
| - QT_REQUIRE_VERSION | ||
| - Q_OBJECT | ||
| - PyObject_HEAD | ||
| IndentAccessModifiers: false | ||
| IndentExternBlock: AfterExternBlock | ||
| IndentGotoLabels: true | ||
| IndentRequiresClause: true | ||
| IndentWrappedFunctionNames: false | ||
| InsertBraces: false | ||
| InsertTrailingCommas: None | ||
| KeepEmptyLinesAtTheStartOfBlocks: true | ||
| LambdaBodyIndentation: OuterScope | ||
| PackConstructorInitializers: BinPack | ||
| RemoveBracesLLVM: false | ||
| RequiresClausePosition: OwnLine | ||
| SeparateDefinitionBlocks: Leave | ||
| ShortNamespaceLines: 1 | ||
| SortUsingDeclarations: false | ||
| SpacesInParentheses: false | ||
| SpacesInSquareBrackets: false | ||
| Standard: Latest | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to consider adding the clang-format hook to a pre-commit-config yaml as 3D Slicer and other related projects have adopted (see https://github.com/Slicer/Slicer/blob/1b1bbb22b4f858ff3d47d196de4ac491a0b9ea5c/.pre-commit-config.yaml#L27-L39). Pre-commit-config yml usage has been adopted by many projects and something that is generally called in a GitHub actions workflow file (e.g. lint.yml) using the pre-commit github action (https://github.com/pre-commit/action). ^This way new styling is applied consistently and enforced for every PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good point! I'm using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jamesobutler -
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! Now just need a lint github workflow to run pre-commit where the workflow will fail if pre-commit detects issues.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had also enabled pre-commit.ci (as I do usually with pre-commit), so indeed the workflow will fail in this case. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/bash | ||
| set -xeuo pipefail | ||
| which -a clang-format-20 > /dev/null \ | ||
| || (echo -e "20.0.0\n$(clang-format${1+-$1} --version | grep -Eo '([0-9]+\.[0-9]+\.[0-9]+)')" | sort -CV ) \ | ||
| || { echo "use '${0} <clang-format-version-not-less-than-20>' to call exact proper version" ; exit 1 ; } | ||
|
|
||
| IGNORED_DIRS=( | ||
| "./generated_cpp_515" | ||
| "./examples" | ||
| "./generator/simplecpp" | ||
| "./build" | ||
| ) | ||
|
|
||
| IGNORE_CMD="" | ||
|
|
||
| for DIR in "${IGNORED_DIRS[@]}"; do | ||
| IGNORE_CMD+=" -path $DIR -o" | ||
| done | ||
|
|
||
| IGNORE_CMD=${IGNORE_CMD% -o} | ||
|
|
||
| find . \( $IGNORE_CMD \) -prune -o -name '*.cpp' -print0 -o -name '*.h' -print0 | xargs -0 clang-format-20 --style=file -i |
Uh oh!
There was an error while loading. Please reload this page.