Skip to content
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

Initial clang-format file #39

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions cpp_guidelines/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
Language: Cpp
Standard: c++17
DisableFormat: false
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
AlignConsecutiveAssignments: true
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
AlignConsecutiveBitFields: true
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
AlignEscapedNewlines: Right
AlignOperands: true
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
AlignTrailingComments: true
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
AllowShortCaseLabelsOnASingleLine: false
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Allman
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 79
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
CommentPragmas: '^ COMMENT pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: false
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
IncludeBlocks: Preserve
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseBlocks: true
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
OperandAlignmentStyle: Align
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😘

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda like middle :-D

ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
TabWidth: 4
UseCRLF: false
UseTab: Never
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I will not convince anybody. But a tab is actually the semantically correct thing to indent. People often confuse this with aligning certain stuff and then complain if it looks different when someone sets a different tab width. Use spaces for alignment and tabs for indenting. This way people can set their tab width to whatever they prefer and the code just displays differently, but has the same semantic indentations.
However, this takes discipline and maybe that effort is spent better elsewhere. New versions of clang-format have AlignWithSpaces which does that, but I never tried it. So sticking with spaces is fine for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs are not available if you write code snippets in online forms where the form e.g. on GitHub

+1 for not allowing tabs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @bernhardmgruber about tabs. I do not like alignment (not invariant under refactoring). Without alignment there is not reason not to indent with tabs.

I kinda see @psychocoderHPC 's point, but unless the coding style indents with a single space, you will not write correctly formatted code in a browser form anyway. I doubt that limitations on snippets should dictate style in the actual code.

Copy link
Member

@ax3l ax3l Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs only make sense if you disallow spaces for intent at the same time. Otherwise things get wildly mixed.
Every editor can set tabs to spaces, do the simple thing, use spaces.

...
Loading