【问题标题】:clang-format multiple BasedOnStyle for multiple Language多种语言的 clang-format 多个 BasedOnStyle
【发布时间】:2020-11-25 08:19:03
【问题描述】:

clang-formatdocumentation中,您可以通过创建一个名为.clang-format的文件来设置clang-format的默认选项。

并且文档中提供的语法如下:

---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
---
Language: JavaScript
# Use 100 columns for JS.
ColumnLimit: 100
---
Language: Proto
# Don't format .proto files.
DisableFormat: true
---
Language: CSharp
# Use 100 columns for C#.
ColumnLimit: 100
...

但是,当我尝试将 BasedOnStyle 变量应用于单个 Language 时,如下所示:

Language: C
BasedOnStyle: LLVM

Language: Cpp
BasedOnStyle: LLVM

Language: Java
BasedOnStyle: Google

Language: JavaScript
BasedOnStyle: Google

它似乎不起作用。

问题是

  1. 是否可以为不同的语言使用不同的BasedOnStyle
  2. 如果是这样,我该怎么做?

【问题讨论】:

    标签: llvm clang-format


    【解决方案1】:

    似乎BasedOnStyle 只定义了Language: Cpp 的样式。

    这可以通过以下命令显示:

    clang-format -style=llvm -dump-config
    

    上面的命令输出成功的样式Language: CppBasedOnStyle 的其他值也是如此。

    所以如果BasedOnStyleLanguage 键和Cpp 以外的值成功,clang-format 将失败。

    因此,无法将不同的预定义样式(LLVMGoogle 等)应用于不同的语言。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-08
      • 2018-03-16
      • 2019-10-09
      相关资源
      最近更新 更多