如何使用clang-format

时间:2016-12-07 16:47:01

标签: c++ code-formatting clang-format

如何在访问修饰符后实现以下缩进:

class A{
public:
int a;
}

应该导致

class A
{
    public:
        int a; // note the indentation
}

clang-format只允许访问修饰符与int a AccessModifierOffset: 0处于同一级别,从而导致

class A
{
    public:
    int a;
}

2 个答案:

答案 0 :(得分:2)

在我工作的地方,我们偶然发现了相同的问题。由于IndentWidth参数在所有位置(类,函数等)都控制缩进,因此您试图实现的目标似乎是不可能的。我认为,下一个最好的方法是保留IndentWidth=4并设置AccessModifierOffset=-2。 这样您就可以:

class Foo
{
  public:
    Foo() = default;
};

bool foo()
{
    return true;
}

答案 1 :(得分:0)

根据clang-format documentationdoCheckSomething("whatever") .then(resultingJson => { // Do whatever you need with the /doCheck data. }) .catch(console.error) // Print errors, in case there are any. 正是为此目的而设计的。用responseJsonAccessModifierOffset格式化您的代码示例,我得到了以下输出:

AccessModifierOffset: -4