如何使用 clang-format 在 switch 中获取单行对齐的 case 语句

How to get single line aligned case statements in a switch, using clang-format

我希望clang-format格式如下:

switch (x)
{
case long_name: return 1;
case sn:        return 2;
}

AllowShortCaseLabelsOnASingleLine 选项使它们在同一行,
但我还没有找到一种方法来使语句 aligned.

截至目前,无法使用 ClangFormat 执行您要求的操作。

官方的解释是:

Each additional style option adds costs to the clang-format project. Some of these costs affect the clang-format development itself, as we need to make sure that any given combination of options work and that new features don’t break any of the existing options in any way. There are also costs for end users as options become less discoverable and people have to think about and make a decision on options they don’t really care about.

The goal of the clang-format project is more on the side of supporting a limited set of styles really well as opposed to supporting every single style used by a codebase somewhere in the wild. [...]

您可以做类似事情的唯一方法是:

  1. 向开发者建议样式选项;
  2. 等待添加所需的样式选项;
  3. 使用能够对齐语句的 ClangFormat 替代方法。

来源:

  1. https://clang.llvm.org/docs/ClangFormatStyleOptions.html#configurable-format-style-options
  2. https://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options