clang-format style options for enums

三世轮回 提交于 2019-11-29 06:51:40

问题


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

i.e.

enum {
    ONE,
    TOW,
    THREE
};

vs.

enum {ONE, TWO, THREE};

EDIT:

Here are the style options i use to match Apple's Objective-C style guide.

http://pastebin.com/0cTEhvBv


回答1:


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
};



回答2:


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



来源:https://stackoverflow.com/questions/23072223/clang-format-style-options-for-enums

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!