I’m trying to make my .clang-format config. Everything is fine, but there is still a little problem.
When I format this:
struct testStruct data[] = {
{.a = 0,
.b = 0},
{.a = 0,
.b = 0},
};
The output will put every element into a single line like this:
struct testStruct data[] = {
{.a = 0, .b = 0},
{.a = 0, .b = 0},
};
If you add a comma at the end of the last element the format will be:
struct testStruct data[] = {
{
.a = 0,
.b = 0,
},
{
.a = 0,
.b = 0,
},
};
I know the better way may is initializing each structure separately:
struct testStruct data[];
data[0] = {
.a = 0,
.b = 0,
}
But, who is controlling these? I can only guess at the AllowShortBlocksOnASingleLine
option, there are too many of them.
My config is here: https://gist.github.com/SourLemonJuice/047f051f2d6365aed547826d22b2a516
Now is:
---
BasedOnStyle: Microsoft
IndentWidth: 4
UseTab: Never
LineEnding: DeriveLF
MaxEmptyLinesToKeep: 2 # for me, 2 empty lines were so common.
# Sorry Linux... But we need some C++ stuff here.
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: MultiLine
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeWhile: false
# BreakBeforeBraces End
AllowShortBlocksOnASingleLine: Never
AllowShortIfStatementsOnASingleLine: Never
IndentCaseLabels: false
IndentPPDirectives: BeforeHash
IncludeBlocks: Preserve # because google c++ guide specifies the order of #include blocks.
SortIncludes: CaseInsensitive
ColumnLimit: 120 # same as Microsoft, don't ask me, I just think it's great.
InsertNewlineAtEOF: true # Who doesn't like n in the file end.
BinPackParameters: true # Microsoft has set this, but I also saw this config.
AlignAfterOpenBracket: Align # TBD, now same as Microsoft.
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AlignOperands: AlignAfterOperator
AlignEscapedNewlines: DontAlign
...
酸柠檬猹 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.