How to get case aligned statements in a string using clang format

I would like clang-format to be formatted like:

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

      

The option AllowShortCaseLabelsOnASingleLine

translates them into one line,
but I haven't found a way to align the aligned statements .

+11


source to share


1 answer


It is currently not possible to accomplish what you are asking for using ClangFormat.

The official explanation why this is so:

Each additional style option increases the cost of the clang-formatted project. Some of these costs affect the actual development of the clang format, as we need to make sure that any given combination of options works and the new features do not in any way violate any of the existing options. There is also a cost to end users as options become less available and people have to think and make decisions about options that they don't really care about.

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

The only way to do something like this is



  1. Suggest a style option to developers;
  2. Wait until the desired style option is added;
  3. Use an alternative to ClangFormat that is capable of aligning statements.

Sources:

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


source







All Articles