xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

Clang-format

Open SylvainCorlay opened this issue 6 years ago • 3 comments

I have a clang-format configuration file that is getting close to our formatting

BasedOnStyle: Mozilla
AccessModifierOffset: '-4'
AlignAfterOpenBracket: Align
AlignEscapedNewlinesLeft: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: 'false'
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakTemplateDeclarations: 'true'
SpaceAfterTemplateKeyword: 'true'
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializersBeforeComma: 'true'
BreakStringLiterals: 'false'
ColumnLimit: '100'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
ConstructorInitializerIndentWidth: '4'
ContinuationIndentWidth: '4'
Cpp11BracedListStyle: 'false'
DerivePointerAlignment: 'false'
DisableFormat: 'false'
ExperimentalAutoDetectBinPacking: 'true'
IndentCaseLabels: 'true'
IndentWidth: '4'
IndentWrappedFunctionNames: 'false'
JavaScriptQuotes: Single
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '2'
NamespaceIndentation: All
ObjCBlockIndentWidth: '4'
ObjCSpaceAfterProperty: 'false'
ObjCSpaceBeforeProtocolList: 'false'
PointerAlignment: Left
ReflowComments: 'true'
SortIncludes: 'false'
SpaceAfterCStyleCast: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: 'false'
SpacesBeforeTrailingComments: '2'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: Cpp11
TabWidth: '4'
UseTab: Never

The main concerns with this concern the way macros are indented, and the fact that clang-format does not allow newlines after access modifiers (such as public:).

The good place to add this in clang-format's codebase is here:

https://github.com/llvm-mirror/clang/blob/5aee9d8635cd4eb119d64e2263a02bb4cfe05a33/lib/Format/UnwrappedLineFormatter.cpp#L939

Adding a Style.EmptylineAfterAccessModifier parameter to the configuration would be easily supported.

SylvainCorlay avatar Nov 22 '18 10:11 SylvainCorlay

we should also check out clang-tidy to remove dead code and stuff like that.

wolfv avatar Nov 22 '18 13:11 wolfv

Did you make progress on automatic code formatting? It would be quite relevant to have automatic formatting from the start, to support clean code from contributors.

emmenlau avatar Mar 07 '19 10:03 emmenlau

It seems that EmptyLineAfterAccessModifier is now supported with clang-format 14.

Possible values are: ELAAMS_Never, ELAAMS_Leave, ELAAMS_Always.

https://clang.llvm.org/docs/ClangFormatStyleOptions.html

SylvainCorlay avatar Jan 04 '22 09:01 SylvainCorlay