【问题标题】:Running clang-format with command line: specify IncludeCategories使用命令行运行 clang-format:指定 IncludeCategories
【发布时间】:2016-05-12 14:38:12
【问题描述】:

我想用命令行运行clang-format(3.8 版)。使用“-style=”选项可以指定 ClangFormatStyleOptions。但是,我无法找到如何指定“IncludeCategories”。在Documentation 中仅描述了如何使用样式配置文件进行操作。 所以我想知道,是否可以用命令行指定它,如果可以,我该怎么做。

【问题讨论】:

    标签: include-path clang-format


    【解决方案1】:

    格式如下:

    -style="{IncludeCategories: [{Regex: 'bla', Priority: 100}, {Regex: 'blubb', Priority: 101}]}"
    

    我是通过实验发现的,无法引用任何来源。


    我正在使用 clang-format-6.0,我观察到以下意外行为。 假设我从一些默认样式开始并使用-dump-config 标志并获得关注IncludeCategories

    IncludeCategories: 
      - Regex:           '^<ext/.*\.h>'
        Priority:        2
      - Regex:           '^<.*\.h>'
        Priority:        1
      - Regex:           '^<.*'
        Priority:        2
      - Regex:           '.*'
        Priority:        3
    

    然后我将IncludeCategories: [{Regex: 'bla', Priority: 100}] 添加到-style 并转储结果,我得到:

    IncludeCategories: 
      - Regex:           'bla'
        Priority:        100
      - Regex:           '^<.*\.h>'
        Priority:        1
      - Regex:           '^<.*'
        Priority:        2
      - Regex:           '.*'
        Priority:        3
    

    所以它会覆盖默认映射的条目,但是当IncludeCategories 添加到-style 时它不会删除映射。我必须用虚拟条目覆盖它,然后附加我的实际条目以获得所需的结果。

    【讨论】:

    • 如果可行,为什么需要资源?恭喜!
    • 我尝试使用此语法来指定 BreakBeforeBraces:自定义 BraceWrapping:AfterClass:false AfterFunction:true 到目前为止没有运气。见stackoverflow.com/questions/71178542/…
    猜你喜欢
    • 1970-01-01
    • 2020-04-18
    • 2017-01-01
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 2020-07-12
    • 2021-09-02
    • 1970-01-01
    相关资源
    最近更新 更多