gpt4 book ai didi

c++ - 使 Clang-Format 忽略换行符的注释

转载 作者:可可西里 更新时间:2023-11-01 15:23:55 43 4
gpt4 key购买 nike

是否可以告诉 Clang-Format 忽略换行操作的注释?这个想法是遵循“代码格式良好,即使注释超过换行边距”的风格。如果代码不超过边距,则不应将代码分成多行,但注释会。

例如

//desired behaviour:
short code = shortCode +
longlonglongCode;
short code = shortCode; //long comment without a line break

//not desired behaviour:
short code =
shortCode; //long comment without a line break

最佳答案

ReflowComments: (bool)

If true, clang-format will attempt to re-flow comments.

false:
// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
/* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */

true:
// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
// information
/* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
* information */

Source

使用ReflowComments: true,启用后它会在//后添加1个空格,并在达到限制时停止注释。

可以使用PenaltyBreakComment进行调整。
例如。阻断刹车线 PenaltyBreakComment: 1000000000

关于c++ - 使 Clang-Format 忽略换行符的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44731978/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com