clang-format style options for enums

前端 未结 3 1533
我在风中等你
我在风中等你 2021-02-04 03:54

Does anyone know how to configure clang-format to keep enum\'s on individual lines?

i.e.

enum {
    ONE,
    TOW,
    THREE
};

vs.

相关标签:
3条回答
  • 2021-02-04 04:11

    Another solution is to use:

    BraceWrapping:
      AfterEnum: true
    

    Which will result in the following:

    enum 
    {
        ONE,
        TOW,
        THREE,
    };
    

    This isn't ideal because it forces a newline before the {, but in my opinion this is worth considering as ColumnLimit = 0 disables all smart code wrapping, and many people may find that not worth giving up.

    0 讨论(0)
  • 2021-02-04 04:21

    Per this answer, setting ColumnLimit to 0 will also achieve this behaviour.

    0 讨论(0)
  • 2021-02-04 04:26

    This was intentionally introduced at some stage (so if you are unable to reproduce the behavior, you are likely on an older version).

    clang-format contracts enums to a single line if all elements fit on one line. This conserves spaces and usually does not decrease readability. There is no style option, but you can override this by either adding a line comment somewhere or by adding a trailing comma after the last enumerator, e.g.:

    enum {
        ONE,
        TOW,
        THREE,
    };
    

    or

    enum {
        ONE,  // This means ...
        TOW,
        THREE
    };
    
    0 讨论(0)
提交回复
热议问题