想象一下,我们有用于格式化日志构建的宏,例如:
LOG(log_level)("key1", "value1")("key2", "value2")...;
在这种情况下,我们将得到格式化结果:
LOG(log_level)
("key1", "value1")("key2", "value2")...;
我尝试了格式化程序配置:
目前,我有下一个 clang-formatter 配置:
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 0
Cpp11BracedListStyle: false
SpacesBeforeTrailingComments: 3
AlignAfterOpenBracket: false
AlignTrailingComments:
Kind: Never
OverEmptyLines: 2
InsertBraces : true
ReflowComments: false
PenaltyBreakComment: 0
DerivePointerAlignment: true
PointerAlignment: Left
AccessModifierOffset: -4
IndentCaseLabels: true
InsertNewlineAtEOF: true
AllowShortCaseLabelsOnASingleLine : false
AllowShortEnumsOnASingleLine : false
AllowShortFunctionsOnASingleLine : false
AllowShortLambdasOnASingleLine : false
AllowShortLoopsOnASingleLine : false
AllowAllParametersOfDeclarationOnNextLine: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
BreakConstructorInitializersBeforeComma: true
SpaceBeforeInheritanceColon: false
BitFieldColonSpacing: After
LOG(log_level)("key1", "value1")("key2", "value2")...;
我如何纠正我的配置以避免在相同情况下断行?
感谢评论中的回答: WhitespaceSensitiveMacros 足以达到目的
WhitespaceSensitiveMacros:
- LOG
结果我对特定的宏没有问题:
AFL_WARN(COMPONENT_NAME)("event", "skip_inserted_data")("reason", "table_removed")("path_id", GetPathId());
在此示例中,格式化程序不会直接在宏使用后进行换行。