From cdd5082b868936dccf330d16b1c134834fa94b21 Mon Sep 17 00:00:00 2001 From: Marc Deop Date: Fri, 1 Mar 2019 20:06:52 +0100 Subject: chore: add .clang-format --- .clang-format | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 .clang-format (limited to '.clang-format') diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..9300f725 --- /dev/null +++ b/.clang-format @@ -0,0 +1,122 @@ +# Inspired by: +# https://code.qt.io/cgit/qt/qt5.git/plain/_clang-format +# https://wiki.qt.io/Qt_Coding_Style +# https://wiki.qt.io/Coding_Conventions +# Further information: https://clang.llvm.org/docs/ClangFormatStyleOptions.html + +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: 0 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: true + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: "^ IWYU pragma:|^!|^:" +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 8 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +PointerBindsToType: false +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... + + -- cgit v1.2.3 From 05d79f971eb9e779227e022ac47e4b78d400c9ec Mon Sep 17 00:00:00 2001 From: Marc Deop Date: Fri, 1 Mar 2019 20:11:51 +0100 Subject: fixup! chore: add .clang-format --- .clang-format | 2 -- 1 file changed, 2 deletions(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index 9300f725..9c8d83e7 100644 --- a/.clang-format +++ b/.clang-format @@ -118,5 +118,3 @@ Standard: Cpp11 TabWidth: 8 UseTab: Never ... - - -- cgit v1.2.3 From c971b924cd62822ed6fb1a0291c483ae73a3ecda Mon Sep 17 00:00:00 2001 From: Marc Deop Date: Sat, 2 Mar 2019 12:24:27 +0100 Subject: fixup! fixup! chore: add .clang-format --- .clang-format | 1 - 1 file changed, 1 deletion(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index 9c8d83e7..12054877 100644 --- a/.clang-format +++ b/.clang-format @@ -44,7 +44,6 @@ BreakBeforeInheritanceComma: false BreakInheritanceList: BeforeColon BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeComma BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true ColumnLimit: 80 -- cgit v1.2.3 From 9087c2fbe8369fd18a47b4edc5ecf20c438ff0ce Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 19 May 2019 15:33:15 +0900 Subject: Update .clang-format as per the field experience --- .clang-format | 214 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 112 insertions(+), 102 deletions(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index 12054877..ffbf6597 100644 --- a/.clang-format +++ b/.clang-format @@ -1,119 +1,129 @@ +# Copyright (C) 2019 Project Quotient +# +# You may use this file under the terms of the LGPL-2.1 license +# See the file LICENSE from this package for details. + +# This is the clang-format configuration style to be used by libQuotient. # Inspired by: # https://code.qt.io/cgit/qt/qt5.git/plain/_clang-format # https://wiki.qt.io/Qt_Coding_Style # https://wiki.qt.io/Coding_Conventions # Further information: https://clang.llvm.org/docs/ClangFormatStyleOptions.html +# For convenience, the file includes commented out settings that we assume +# to borrow from the WebKit style. The values for such settings try to but +# are not guaranteed to coincide with the latest version of the WebKit style. + --- -Language: Cpp -# BasedOnStyle: WebKit -AccessModifierOffset: 0 +Language: Cpp +BasedOnStyle: WebKit +#AccessModifierOffset: -4 AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlines: Right -AlignOperands: false -AlignTrailingComments: false -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterClass: true - AfterControlStatement: false - AfterEnum: false - AfterFunction: true - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false +#AlignConsecutiveAssignments: false +#AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +#AlignTrailingComments: false +#AllowAllParametersOfDeclarationOnNextLine: true +#AllowShortBlocksOnASingleLine: false +#AllowShortCaseLabelsOnASingleLine: false +#AllowShortFunctionsOnASingleLine: All +#AllowShortIfStatementsOnASingleLine: false +#AllowShortLoopsOnASingleLine: false +#AlwaysBreakAfterReturnType: None +#AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +#BinPackArguments: true +#BinPackParameters: true +BraceWrapping: + AfterClass: true + AfterControlStatement: false + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Custom -BreakBeforeInheritanceComma: false +#BreakBeforeInheritanceComma: false BreakInheritanceList: BeforeColon -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -ColumnLimit: 80 -CommentPragmas: "^ IWYU pragma:|^!|^:" +#BreakBeforeTernaryOperators: true +#BreakConstructorInitializersBeforeComma: false +#BreakConstructorInitializers: BeforeComma +#BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^!|^:' CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 8 +#ConstructorInitializerAllOnOneLineOrOnePerLine: false +#ConstructorInitializerIndentWidth: 4 +#ContinuationIndentWidth: 4 Cpp11BracedListStyle: false -DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: false -ForEachMacros: +#DerivePointerAlignment: false +FixNamespaceComments: true +ForEachMacros: - foreach - Q_FOREACH - - BOOST_FOREACH -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - - Regex: '.*' - Priority: 1 -IncludeIsMainRegex: '(Test)?$' -IndentCaseLabels: false -IndentPPDirectives: None -IndentWidth: 4 -IndentWrappedFunctionNames: false -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: All -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: true -ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 + - forever +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^ Date: Thu, 20 Jun 2019 16:37:47 +0900 Subject: .clang-format: fine-tune penalties --- .clang-format | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index ffbf6597..d0cee866 100644 --- a/.clang-format +++ b/.clang-format @@ -96,11 +96,11 @@ IndentPPDirectives: AfterHash #MacroBlockEnd: '' #MaxEmptyLinesToKeep: 1 #NamespaceIndentation: Inner -PenaltyBreakAssignment: 50 -PenaltyBreakBeforeFirstCallParameter: 70 -#PenaltyBreakComment: 300 +PenaltyBreakAssignment: 30 +PenaltyBreakBeforeFirstCallParameter: 50 +PenaltyBreakComment: 45 #PenaltyBreakFirstLessLess: 120 -#PenaltyBreakString: 1000 +PenaltyBreakString: 200 #PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 20 PenaltyReturnTypeOnItsOwnLine: 60 -- cgit v1.2.3 From 45c66cc358c251fa316d993ec251982486530760 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 23 Jun 2019 17:50:15 +0900 Subject: .clang-format: Skip on CommentPragmas We do want doc-comments to be formatted as well. --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index d0cee866..9bb23403 100644 --- a/.clang-format +++ b/.clang-format @@ -59,7 +59,7 @@ BreakInheritanceList: BeforeColon #BreakConstructorInitializers: BeforeComma #BreakStringLiterals: true ColumnLimit: 80 -CommentPragmas: '^!|^:' +#CommentPragmas: '^!|^:' CompactNamespaces: false #ConstructorInitializerAllOnOneLineOrOnePerLine: false #ConstructorInitializerIndentWidth: 4 -- cgit v1.2.3 From 6c4e78e8a55eab681393faff888448c887bb7127 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 9 Jul 2019 12:32:48 +0900 Subject: CMakeLists.txt: fix things around clang-format, inherit CLANG_FORMAT_ARGS --- .clang-format | 4 ++-- .travis.yml | 1 + CMakeLists.txt | 7 ++++--- CONTRIBUTING.md | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index 9bb23403..a0b2ba11 100644 --- a/.clang-format +++ b/.clang-format @@ -32,7 +32,7 @@ AlignOperands: true #AllowShortLoopsOnASingleLine: false #AlwaysBreakAfterReturnType: None #AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: Yes +#AlwaysBreakTemplateDeclarations: true #BinPackArguments: true #BinPackParameters: true BraceWrapping: @@ -53,7 +53,7 @@ BraceWrapping: BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Custom #BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon +#BreakInheritanceList: BeforeColon # Only supported since clang-format 7 #BreakBeforeTernaryOperators: true #BreakConstructorInitializersBeforeComma: false #BreakConstructorInitializers: BeforeComma diff --git a/.travis.yml b/.travis.yml index 6880844b..cb932120 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ addons: - qt57base - qt57multimedia - valgrind + - clang-format-6.0 matrix: include: diff --git a/CMakeLists.txt b/CMakeLists.txt index 13f6fcfb..a40d4385 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ if (ABS_API_DEF_PATH AND ABS_GTAD_PATH) if (ABS_CLANG_FORMAT) message( STATUS "clang-format is at ${ABS_CLANG_FORMAT}") else () - message( STATUS "${CLANG_FORMAT} is NOT FOUND; --target update-format-api disabled") + message( STATUS "${CLANG_FORMAT} is NOT FOUND; API files won't be reformatted") endif () endif () find_package(Git) @@ -192,18 +192,19 @@ if (MATRIX_DOC_PATH AND GTAD_PATH) ${API_DEFS} VERBATIM ) - if (CLANG_FORMAT) + if (ABS_CLANG_FORMAT) # TODO: list(TRANSFORM) is available from CMake 3.12 foreach (S ${api_SRCS}) string (REGEX REPLACE ".cpp$" ".h" H ${S}) list(APPEND api_HDRS ${H}) endforeach() - set(CLANG_FORMAT_ARGS -i -sort-includes -verbose) + set(CLANG_FORMAT_ARGS -i -sort-includes ${CLANG_FORMAT_ARGS}) add_custom_command(TARGET update-api POST_BUILD COMMAND ${ABS_CLANG_FORMAT} ${CLANG_FORMAT_ARGS} ${api_SRCS} COMMAND ${ABS_CLANG_FORMAT} ${CLANG_FORMAT_ARGS} ${api_HDRS} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} VERBATIM + COMMENT Formatting files ) endif() endif() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d7fa19bd..fb8ff436 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -170,9 +170,9 @@ Because before both original authors of libQuotient had to do monkey business of (quotient-im/matrix-doc is a fork that's known to produce working code; you may want to use your own fork if you wish to alter something in the API). 4. If you plan to submit a PR or just would like the generated code to be - formatted, you should either ensure you have clang-format in your PATH or - pass the _absolute_ path to it by adding `-DCLANG_FORMAT=` - to the CMake invocation below. + formatted, you should either ensure you have clang-format (version 6 at least) + in your PATH or pass the _absolute_ path to it by adding + `-DCLANG_FORMAT=` to the CMake invocation below. #### Generating CS API contents 1. Pass additional configuration to CMake when configuring libQuotient: -- cgit v1.2.3 From 8dcf42e70578c8c37fe3200c3e99ffa8d80d03c3 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 2 Aug 2019 09:35:38 +0900 Subject: .clang-format: Bring back AlwaysBreakTemplateDeclarations It was accidentally left commented out in trying to support clang-format 5. Now that we're embracing clang-format 6+ only, it really should be on. --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index a0b2ba11..f8a3b222 100644 --- a/.clang-format +++ b/.clang-format @@ -32,7 +32,7 @@ AlignOperands: true #AllowShortLoopsOnASingleLine: false #AlwaysBreakAfterReturnType: None #AlwaysBreakBeforeMultilineStrings: false -#AlwaysBreakTemplateDeclarations: true +AlwaysBreakTemplateDeclarations: true #BinPackArguments: true #BinPackParameters: true BraceWrapping: -- cgit v1.2.3 From accf1b2ac33eaa91ec4030cb77079d5a26680a0b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 2 Aug 2019 13:56:26 +0900 Subject: .clang-format: Enable ConstructorInitializerAllOnOneLineOrOnePerLine --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index f8a3b222..682db3fb 100644 --- a/.clang-format +++ b/.clang-format @@ -61,7 +61,7 @@ BreakBeforeBraces: Custom ColumnLimit: 80 #CommentPragmas: '^!|^:' CompactNamespaces: false -#ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true #ConstructorInitializerIndentWidth: 4 #ContinuationIndentWidth: 4 Cpp11BracedListStyle: false -- cgit v1.2.3 From 1a1ea8fc87e827fa44c80ff30277e3bee62f4ebb Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 2 Aug 2019 19:56:34 +0900 Subject: .clang-format: Alter brace wrapping to (mostly) match WebKit style --- .clang-format | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index 682db3fb..40262bc3 100644 --- a/.clang-format +++ b/.clang-format @@ -35,15 +35,15 @@ AlignOperands: true AlwaysBreakTemplateDeclarations: true #BinPackArguments: true #BinPackParameters: true -BraceWrapping: - AfterClass: true +BraceWrapping: + AfterClass: false AfterControlStatement: false - AfterEnum: true + AfterEnum: false AfterFunction: true - AfterNamespace: true - AfterStruct: true - AfterUnion: true - AfterExternBlock: true + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false BeforeCatch: false BeforeElse: false IndentBraces: false -- cgit v1.2.3 From 904fb065c07894978845003bac156616da21274e Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 18 Aug 2019 08:23:27 +0900 Subject: .clang-format: minor tweaks in penalties --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to '.clang-format') diff --git a/.clang-format b/.clang-format index 40262bc3..e114580e 100644 --- a/.clang-format +++ b/.clang-format @@ -96,8 +96,8 @@ IndentPPDirectives: AfterHash #MacroBlockEnd: '' #MaxEmptyLinesToKeep: 1 #NamespaceIndentation: Inner -PenaltyBreakAssignment: 30 -PenaltyBreakBeforeFirstCallParameter: 50 +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 70 PenaltyBreakComment: 45 #PenaltyBreakFirstLessLess: 120 PenaltyBreakString: 200 -- cgit v1.2.3