如何配置clang-format使注释与左大括号保持同行?
解决clang-format将大括号后注释移至新行的问题
在现有clang-format配置中添加KeepCommentsWithStatements: true项即可实现需求,修改后的完整配置如下:
BasedOnStyle: Google Language: Cpp ColumnLimit: 120 KeepCommentsWithStatements: true
配置说明
KeepCommentsWithStatements: true:该配置会强制让注释与它所属的代码语句保持在同一行,避免clang-format将左大括号后的注释单独移至新行。- 保留
BasedOnStyle: Google可以维持Google风格的其他格式化规则,比如函数、类、命名空间的大括号单独换行,循环、条件语句的大括号与主体同行等。
修改后,clang-format会输出你期望的格式化效果:
foreach(const QString& value, list_string) { /// value must be latter container inclusion type if (value == "c") { break; } qDebug() << value; }
内容的提问来源于stack exchange,提问作者Spike Aaron
相关产品推荐
相关产品推荐

