枚举的 clang 格式样式选项 [英] clang-format style options for enums

查看:34
本文介绍了枚举的 clang 格式样式选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何配置 clang-format 以将枚举保留在单独的行上?

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

enum {
    ONE,
    TOW,
    THREE
};

对比

enum {ONE, TWO, THREE};

以下是我用来匹配 Apple 的 Objective-C 样式指南的样式选项.

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

http://pastebin.com/0cTEhvBv

推荐答案

这是在某个阶段有意引入的(因此,如果您无法重现该行为,您可能使用的是旧版本).

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 如果所有元素都在一行中,则将枚举收缩为一行.这可以节省空间并且通常不会降低可读性.没有样式选项,但您可以通过在某处添加行注释或在最后一个枚举器后添加尾随逗号来覆盖它,例如:

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

enum {
    ONE,  // This means ...
    TOW,
    THREE
};

这篇关于枚举的 clang 格式样式选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆