问题描述
在此输入上,我正在运行clang-format
,并带有一个仅指定.clang-format
的{{1}}文件(无效的C ++,但这并不重要)
Language: Cpp
我得到以下输出:
const auto SOME_VARIABLE_NAME = {{"key",{ {"key2",std::array{ 0,}},}}};
我会更接近以下输出:
const auto SOME_VARIABLE_NAME = {{"key",{
{"key2",std::array{
0,}}};
我不确定为什么clang-format在每个const auto SOME_VARIABLE_NAME = {{"key",std::array{0,0}},}}};
之后,在第50列附近放置一个换行符。
我应该在我的0
中添加什么设置来实现这一目标?
我尝试了一些我认为可能相关的说明符,但无济于事:
-
.clang-format
-
AllowAllParametersOfDeclarationOnNextLine: true
-
AllowShortFunctionsOnASingleLine: true
-
BinPackParameters: true
-
BreakBeforeBinaryOperators: false
-
ColumnLimit: 120
-
ConstructorInitializerAllOnOneLineOrOnePerLine: true
-
Cpp11BracedListStyle: false
-
IndentFunctionDeclarationAfterType: true
-
PenaltyBreakBeforeFirstCallParameter: 1000
编辑:仍然有此问题。在第一个括号之后添加评论,以至少将括号进一步向左移动:
Standard: Cpp11
解决方法
问题在于紧接大括号前的结尾逗号。尾部逗号(在c++
中是可选的)告诉clang-format
将每个元素放在单独的行上。我不知道此约定来自何处,似乎也不是documented。就您而言,这似乎正在妨碍您。
如果仅删除最后一个“ 0”之后的逗号,则默认的clang-format
设置将产生以下结果:
const auto SOME_VARIABLE_NAME = {{"key",{
{"key2",std::array{0,0}},}}};
...这与您要求的不完全相同,但是非常接近。