c++ - clang-format 重写 WebKit 风格的多行注释

标签 c++ clang-format

我正在尝试使用 clang-format 来清理我存储库中的代码。我们使用 WebKit 样式作为格式化的基础,但我们也想确保多行注释的格式正确。

根据我的理解,可以通过这样定义 .clang-format 文件来覆盖给定样式的格式设置规则:

BasedOnStyle: WebKit
AlignTrailingComments: true

这样 clang-format 应该对齐尾随的注释。

给定输入文件:

    /**
     * This is a multi-line comment
     */
    void function() {
        /**
         * This is comment inside the function
         */
    }

我的期望是以下输出

/**
 * This is a multi-line comment
 */
void function()
{
    /**
     * This is comment inside the function
     */
}

但是我得到的是:

/**
     * This is a multi-line comment
     */
void function()
{
    /**
         * This is comment inside the function
         */
}

我已经尝试将 Webkit 的格式化选项转储到 .clang-format 文件中,并将 AlignTrailingComments 从 false 更改为 true。这也没有关系。

Webkit 样式中是否有某些选项干扰了 AlignTrailingComments 选项?

最佳答案

AlignTrailingComments 对齐连续行中尾随代码的注释:

int short;        // short
int longlonglong; // long

关于c++ - clang-format 重写 WebKit 风格的多行注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35712729/

相关文章:

c++ - C++ 构造函数名称后面的冒号有什么作用?

c++ - 消除连接字符串的硬编码

c++ - 需要将一行中的数字与字符串分开,在C++中用 ';'(25; 16; 67; 13)分隔

Objective-C Clang-Format 方法大括号中断

c++ - Omnet + MySQL 不工作

c++ - 指向数组参数的双指针错误

c++ - 如何使用 clang 格式分隔 lambda 的尾随返回类型

c++ - 防止 clang-format 在 -> 运算符处换行

c++ - 如何以 clang 格式强制使用 east const?

c++ - 可以 clang-format 将大括号添加到单行if语句等