From f9cd4eb9e82a46a45cca2bf3fc9eaaf5ce287c8b Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Sun, 26 Mar 2023 07:34:22 -0400 Subject: [PATCH] fix: adjust clang-format to reflect the reality --- .clang-format | 100 +++++++++++++++--- ...to use .clang-format to format the code.md | 7 +- 2 files changed, 94 insertions(+), 13 deletions(-) diff --git a/.clang-format b/.clang-format index 00140eaa..e9510fe4 100644 --- a/.clang-format +++ b/.clang-format @@ -1,23 +1,35 @@ -# Format Style Options - Created with Clang Power Tools --- -AccessModifierOffset: -1 +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 AlignAfterOpenBracket: Align +AlignArrayOfStructures: None AlignConsecutiveAssignments: Consecutive +AlignConsecutiveBitFields: Consecutive +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: Consecutive AlignEscapedNewlines: Left AlignOperands: DontAlign AlignTrailingComments: true AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: Empty -AllowShortLambdasOnASingleLine: None +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None AllowShortEnumsOnASingleLine: false AlwaysBreakBeforeMultilineStrings: true -BasedOnStyle: LLVM +AlwaysBreakTemplateDeclarations: MultiLine BinPackArguments: false BinPackParameters: false -BraceWrapping: +BraceWrapping: AfterCaseLabel: false AfterClass: true - AfterControlStatement: false + AfterControlStatement: Never AfterEnum: false AfterFunction: true AfterNamespace: false @@ -35,35 +47,99 @@ BraceWrapping: BeforeWhile: false BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: AfterColon BreakStringLiterals: false ColumnLimit: 120 +QualifierAlignment: Leave +CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth : 2 ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true DeriveLineEnding: false -EmptyLineBeforeAccessModifier: Leave +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Leave +EmptyLineBeforeAccessModifier: Always ExperimentalAutoDetectBinPacking: true -FixNamespaceComments: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - Q_FOREACH IncludeBlocks: Regroup IndentCaseLabels: true IndentAccessModifiers: false +IndentCaseBlocks: false +IndentGotoLabels: true IndentPPDirectives: BeforeHash +IndentExternBlock: AfterExternBlock +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertTrailingCommas: None +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' MaxEmptyLinesToKeep: 2 -NamespaceIndentation: Inner +NamespaceIndentation: None PackConstructorInitializers: Never +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 PointerAlignment: Middle +PPIndentWidth: -1 +ReferenceAlignment: Pointer ReflowComments: false -SortIncludes: false +SortIncludes: Never +RequiresClausePosition: OwnLine +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 SortUsingDeclarations: false -SpaceAfterCStyleCast: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: false SpaceBeforeInheritanceColon: false -SpaceBeforeParens: Never +SpaceBeforeParens: ControlStatements +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 SpacesInAngles: true SpacesInConditionalStatement: true +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 SpacesInParentheses: true SpacesInSquareBrackets: true +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +UseCRLF: false UseTab: Never ... diff --git a/howto/how to use .clang-format to format the code.md b/howto/how to use .clang-format to format the code.md index f117c571..99bf3f7c 100644 --- a/howto/how to use .clang-format to format the code.md +++ b/howto/how to use .clang-format to format the code.md @@ -6,8 +6,13 @@ the project has included a .clang-format as the code guideline. # How to use this file -## QtCreator: +## CommandLine +Stash changes via `git add files` then `git-clang-format` + + + +## QtCreator: Check the steps in the following webpage. https://doc.qt.io/qtcreator/creator-indenting-code.html#automatic-formatting-and-indentation