editorconfig.org
https://editorconfig.org/
EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs. The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles. EditorConfig files are easily readable and they work nicely with version control systems.
Having consistent coding styles makes perfect sense!
Therefore I would suggest indent_size = 4 for all languages
@mck1117 see https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022
It was mentioned that some tooling to help enforce/automate style would be more preferred: i.e. https://clang.llvm.org/docs/ClangFormat.html
Taking some notes about the style I'm seeing in some prominent files, focusing on firmware//C/C++ for now (e.g. firmware/rusefi.cpp, firmware/controllers/math/throttle_model.cpp, firmware/controllers/engine_cycle/knock_controller.cpp; please suggest others).
- Tab characters for indentation, presumably 8 space tab stop
bool KnockControllerBase::onKnockSenseCompleted(uint8_t cylinderNumber, float dbv, efitick_t lastKnockTime) { bool isKnock = dbv > m_knockThreshold; // Per-cylinder peak detector float cylPeak = peakDetectors[cylinderNumber].detect(dbv, lastKnockTime); m_knockCyl[cylinderNumber] = roundf(cylPeak); // .... } - One True Brace style
... like the K&R style, but functions are formatted like multi-statement blocks with the opening brace on the same line as the declaration, and braces are not omitted for a single-statement block
bool is_negative(int x) { if (x < 0) { return true; } else { return false; } }
This is what I've come up with so far, using clang-format v20; v19 works, but has limited BinPackParameters support.
BreakInheritanceList has a caveat that it only works when ColumnLimit is set, but ColumnLimit is used by a lot of other options to determine if a line "fits" or a break/wrap is necessary, so setting it unfathomably high (a work-around) has negative side-effects: I've set it to 160 arbitrarily, though I wanted to use 0 until we can settle on a limit.
This also bases around using tab characters for indentation, with an assumed width of 8 characters. This starts to matter when using e.g. AlignConsecutive... options, or aligning to names rather than strict indentation -- I think this isn't a style we use much, so maybe a low concern. Personally, I'm a fan of (four) spaces for indentation; 8-wide tab makes my eyes dizzy.
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
#DisableFormat: true
Language: Cpp
Standard: Latest
#Standard: Auto
AccessModifierOffset: -8
AlignAfterOpenBracket: BlockIndent
#AlignAfterOpenBracket: AlwaysBreak
#AlignAfterOpenBracket: DontAlign
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseExpressionOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
#AllowShortFunctionsOnASingleLine: None
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
#AllowShortLambdasOnASingleLine: All
#AllowShortLambdasOnASingleLine: Empty
BinPackArguments: false
BinPackParameters: OnePerLine #clang-format v20
#BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBraces: Custom
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
#ColumnLimit: 0
ColumnLimit: 160
#ColumnLimit: 10000
CompactNamespaces: false
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
DerivePointerAlignment: false
FixNamespaceComments: true
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: NoIndent
IndentGotoLabels: false
IndentWidth: 8
NamespaceIndentation: None
PackConstructorInitializers: Never
#PackConstructorInitializers: CurrentLine #https://github.com/llvm/llvm-project/issues/61938
PointerAlignment: Middle
PPIndentWidth: 0
QualifierAlignment: Right
#ReflowComments: true
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 0
SortIncludes: Never
#SortIncludes: CaseSensitive
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
#SpaceAroundPointerQualifiers:
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
#SpaceBeforeParens: Custom
#SpaceBeforeParensOptions:
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
#SpaceInEmptyBlock: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
#SpacesInParens: Custom
#SpacesInParensOptions:
# ExceptDoubleParentheses: false
# InConditionalStatements: false
# InCStyleCasts: false
# InEmptyParentheses: false
# Other: false
SpacesInSquareBrackets: false
TabWidth: 8
UseTab: Always