From 321e72cb6d47cb22601acb618c03be79e055a7f7 Mon Sep 17 00:00:00 2001 From: Pranam Lashkari Date: Sun, 11 Apr 2021 21:49:27 +0530 Subject: [PATCH 1/2] introduce official clang-format --- .clang-format | 140 +++++++++++++++ .gitignore | 3 - example/clang-format/.clang-format | 263 ----------------------------- example/clang-format/README.md | 17 -- 4 files changed, 140 insertions(+), 283 deletions(-) create mode 100644 .clang-format delete mode 100644 example/clang-format/.clang-format delete mode 100644 example/clang-format/README.md diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..215f72eead --- /dev/null +++ b/.clang-format @@ -0,0 +1,140 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM+WebKit+Chromium +AccessModifierOffset: -4 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveMacros: AcrossEmptyLinesAndComments +AlignConsecutiveAssignments: AcrossEmptyLinesAndComments +AlignConsecutiveBitFields: AcrossEmptyLinesAndComments +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortEnumsOnASingleLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: true +BreakInheritanceList: BeforeComma +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 100 +CommentPragmas: '^!<' +CompactNamespaces: true +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^' + Priority: 3 + - Regex: '.*' + Priority: 4 +IncludeIsMainRegex: '' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentWidth: 4 +IndentWrappedFunctionNames: true +InsertTrailingCommas: None +JavaScriptQuotes: Double +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 30 +PenaltyBreakComment: 10 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 10 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 100 +PenaltyReturnTypeOnItsOwnLine: 100 +PointerAlignment: Left +ReflowComments: false +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: 2 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Latest +TabWidth: 4 +UseCRLF: false +UseTab: Never +... diff --git a/.gitignore b/.gitignore index f16ee331e4..57ffbf6e2c 100644 --- a/.gitignore +++ b/.gitignore @@ -17,9 +17,6 @@ doc/warnings.txt *.code-workspace out -# Clang/LLVM -/.clang-format - # CMake /*build* /cmake-build-debug/ diff --git a/example/clang-format/.clang-format b/example/clang-format/.clang-format deleted file mode 100644 index 4394c4a091..0000000000 --- a/example/clang-format/.clang-format +++ /dev/null @@ -1,263 +0,0 @@ -# Annotated clang-format configuration for Boost.GIL -# -# Based in clang-format 5.0 options: -# http://releases.llvm.org/5.0.0/tools/clang/docs/ClangFormatStyleOptions.html -# ---- -Language: Cpp - -# The style used for all options not specifically set in the configuration. -# NOTE: Strive to specify all options, so it is unnecessary to inherit any defaults. -#BasedOnStyle: WebKit+Chromium - -# Use no space offset for class access modifiers, eg. public. -AccessModifierOffset: -4 - -# How to horizontally align arguments after an open bracket (angle and square too). -AlignAfterOpenBracket: AlwaysBreak - -# Align the assignment operators of consecutive lines. -AlignConsecutiveAssignments: true - -# Align the declaration names of consecutive lines. -AlignConsecutiveDeclarations: false - -# How to align backslashes in escaped newlines, i.e. preprocessor macro continuation. -AlignEscapedNewlines: Right - -# Horizontally align operands of binary and ternary expressions. -AlignOperands: true - -# Align trailing comments in consecutive lines -AlignTrailingComments: true - -# If the function declaration doesn't fit on a line, allow putting all parameters -# of a function declaration onto the next line even if BinPackParameters is false. -AllowAllParametersOfDeclarationOnNextLine: true - -# Allows contracting simple braced statements to a single line. -AllowShortBlocksOnASingleLine: false - -# Allows contracting short case labels to a single line. -AllowShortCaseLabelsOnASingleLine: true - -# Dependent on the value, int f() { return 0; } can be put on a single line. -AllowShortFunctionsOnASingleLine: None - -# Dependent on the value, if (a) return; can be put on a single line. -AllowShortIfStatementsOnASingleLine: false - -# Dependent on the value, while (true) continue; can be put on a single line. -AllowShortLoopsOnASingleLine: false - -# This option is deprecated and is retained for backwards compatibility. -#AlwaysBreakAfterDefinitionReturnType: AllDefinitions - -# Always break before multiline string literals. -AlwaysBreakBeforeMultilineStrings: true - -# Always break after the template<...> of a template declaration. -AlwaysBreakTemplateDeclarations: true - -# Place function call arguments on the same or separate lines. -# See also AllowAllParametersOfDeclarationOnNextLine. -BinPackParameters: false - -# Custom control of individual brace wrapping cases -# See BreakBeforeBraces: Custom -BraceWrapping: - AfterClass: true - AfterControlStatement: true - AfterEnum: true - AfterFunction: true - AfterNamespace: false - AfterObjCDeclaration: true - AfterStruct: true - AfterUnion: true - BeforeCatch: true - BeforeElse: true - IndentBraces: false - -BreakBeforeBinaryOperators: None - -# Custom, then BraceWrapping applies -BreakBeforeBraces: Custom - -# In the class inheritance break before : and , if there is multiple inheritance. -BreakBeforeInheritanceComma: true - -# Place ternary operators after line breaks, so ? and : lead lines with operands. -BreakBeforeTernaryOperators: true - -# Break constructor initializers before the colon and commas, -# and align the commas with the colon. -BreakConstructorInitializers: BeforeComma - -# Allow breaking string literals when formatting. -BreakStringLiterals: true - -# Keep lines under 100 characters/columns long. -ColumnLimit: 100 - -# Regular expression for comments with special meaning, which should not be changed. -CommentPragmas: '^!<' - -# Consecutive namespace declarations will be on the same line wrapping -# any overflowing namespace. -CompactNamespaces: true - -# If constructor initializers don't fit on a line, put each initializer on its own line. -ConstructorInitializerAllOnOneLineOrOnePerLine: true - -# Number of characters to use for indentation of constructor initializer lists. -ConstructorInitializerIndentWidth: 4 - -# Indent width for line continuations. -ContinuationIndentWidth: 4 - -# Format braced lists as best suited for C++11 braced lists. -Cpp11BracedListStyle: true - -# Whether to analyze formatted file for the most common alignment of & and *. -# If true, thenPointerAlignment is then used only as fallback. -DerivePointerAlignment: false - -# Disables formatting completely. -DisableFormat: false - -# Whether clang-format should detect function calls and definitions formatting -# with one parameter per line. EXPERIMENTAL -ExperimentalAutoDetectBinPacking: false - -# Add missing namespace end comments and fix invalid existing ones. -FixNamespaceComments: true - -# Expect no for-each MACROS, for sake! -ForEachMacros: [] - -# Regular expressions for categories used for ordering #includes -# TODO: Refine -# Regex: '^<(c?(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|uchar|wchar|wctype)(.h)?|(experimental/)?(algorithm|any|chrono|deque|filesystem|forward_list|functional|future|list|map|memory|memory_resource|numeric|optional|ratio|regex|set|string|string_view|system_error|tuple|type_traits|unordered_map|unordered_set|utility|vector)|array|atomic|bitset|charconv|codecvt|compare|complex|condition_variable|cstdatomic|exception|exception_list|execution|execution_policy|fstream|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|locale|mutex|new|ostream|queue|random|scoped_allocator|shared_mutex|sstream|stack|stdexcept|streambuf|strstream|syncstream|thread|typeindex|typeinfo|valarray|variant)>' -IncludeCategories: - - Regex: '^' - Priority: 3 - - Regex: '.*' - Priority: 4 - -# Regular expression to help file-to-main-include mapping. -# Boost.GIL is header-only, no mapping necessary. -#IncludeIsMainRegex: '' - -# Indent case labels one level from the switch statement. -IndentCaseLabels: false - -# For backward compatibility, see IndentWrappedFunctionNames -#IndentFunctionDeclarationAfterType: false - -# Indent 4 spaces at a time. -IndentWidth: 4 - -# Indent if a function definition or declaration is wrapped after the type. -IndentWrappedFunctionNames: true - -# Do not keep empty line at the start of blocks. -KeepEmptyLinesAtTheStartOfBlocks: false - -# Boost.GIL does not use preprocessor macro blocks. -#MacroBlockBegin: "" -#MacroBlockEnd: "" - -# Maximum number of consecutive empty lines to keep -MaxEmptyLinesToKeep: 2 - -# Do not indent inside namespaces -NamespaceIndentation: None - -# -# Penalties is a complex machinery, see https://stackoverflow.com/a/46749925/151641 -# TODO: Refine - -# Penalty for breaking around an assignment operator. -PenaltyBreakAssignment: 10 - -# Penalty for breaking a function call after call(. -PenaltyBreakBeforeFirstCallParameter: 30 - -# Penalty for each line break introduced inside a comment. -PenaltyBreakComment: 10 - -# Penalty for breaking before the first << -PenaltyBreakFirstLessLess: 120 - -# Penalty for each line break introduced inside a string literal. -PenaltyBreakString: 10 - -# Penalty for each character outside of the column limit. -PenaltyExcessCharacter: 100 - -# Penalty for putting the return type of a function onto its own line. -# HINT: Use auto and trailing return type -PenaltyReturnTypeOnItsOwnLine: 100 - -# Pointer and reference alignment style. -PointerAlignment: Left - -# Prevent clang-format to attempt to re-flow comments. -# TODO: If we allow, any chance it will break Doxygen comments? -ReflowComments: false - -# Sort #include-s -SortIncludes: true - -# Sort using declarations. -# TODO: Let's see how it works, if terribly then switch off -SortUsingDeclarations: true - -# No space inserted after C style casts. -SpaceAfterCStyleCast: false - -# Insert after the 'template' keyword. -SpaceAfterTemplateKeyword: true - -# Fix space around assignment operators. -SpaceBeforeAssignmentOperators: true - -# Do not insert space before a C++11 braced list used to initialize an object -SpaceBeforeCpp11BracedList: false - -# Put space before opening parentheses only after control keywords (for/if/while...). -SpaceBeforeParens: ControlStatements - -# No space may be inserted into (). -SpaceInEmptyParentheses: false - -# Number of spaces before trailing line comments (//) -SpacesBeforeTrailingComments: 2 - -# No spaces after < and before > in template argument lists. -SpacesInAngles: false - -# No spaces are inserted inside container literals. -SpacesInContainerLiterals: false - -# No spaces inserted into C style casts. -SpacesInCStyleCastParentheses: false - -# No spaces will be inserted after ( and before ). -SpacesInParentheses: false - -# No spaces will be inserted after [ and before ]. -SpacesInSquareBrackets: false - -# Allow double brackets such as std::vector>. -Standard: Cpp11 - -# Boost.GIL uses spaces ONLY -TabWidth: 4 - -UseTab: Never -... diff --git a/example/clang-format/README.md b/example/clang-format/README.md deleted file mode 100644 index bef06193bc..0000000000 --- a/example/clang-format/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Boost.GIL Clang-Format - -This is an _example_ of `.clang-format` file which offers _good enough_ -configuration and may be _useful_ when writing code for GIL, not required though. - -This is **not** a complete configuration! - -It does not cover all the recommended or preferred ways of formatting the code for GIL. -It may be necessary to manually tweak the formatting generated by this `.clang-format` file. -For example, there is a bug in clang-format that does not allow spacing and breaking -trailing return types properly. More in details can be found in the -[brainstorm of .clang-format proposal](https://github.com/boostorg/gil/pull/87). - -It has been successfully used with clang-format 8 or later. - -If you wish to use this file with `clang-format`, copy it to the root directory of GIL -sources, to `libs/gil/.clang-format`. From a3af6221ce0ea2748bb52f50af18b7b58a87f479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Fri, 7 May 2021 01:34:49 +0200 Subject: [PATCH 2/2] mloskot's proposal with initial tweaks to this .clang-format This is intermediate commit to clearly show the .clang-format tweaks that I'd like to propose to @lpranam 's original. --- .clang-format | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.clang-format b/.clang-format index 215f72eead..949024cc49 100644 --- a/.clang-format +++ b/.clang-format @@ -4,11 +4,11 @@ Language: Cpp AccessModifierOffset: -4 AlignAfterOpenBracket: AlwaysBreak AlignConsecutiveMacros: AcrossEmptyLinesAndComments -AlignConsecutiveAssignments: AcrossEmptyLinesAndComments +AlignConsecutiveAssignments: None AlignConsecutiveBitFields: AcrossEmptyLinesAndComments AlignConsecutiveDeclarations: None AlignEscapedNewlines: Right -AlignOperands: true +AlignOperands: AlignAfterOperator AlignTrailingComments: true AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: false @@ -45,7 +45,7 @@ BraceWrapping: SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true -BreakBeforeBinaryOperators: None +BreakBeforeBinaryOperators: All BreakBeforeBraces: Custom BreakBeforeInheritanceComma: true BreakInheritanceList: BeforeComma @@ -70,7 +70,7 @@ ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH -IncludeBlocks: Preserve +IncludeBlocks: Regroup IncludeCategories: - Regex: '^