c++ - clang-format -style=file 在 Ubuntu 18.04 中不起作用

标签 c++ clang ubuntu-18.04 clang-format

我在 Ubuntu 18.04 上使用 clang-format 9。
我已阅读 clang-format它说的文档:

clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the .clang-format or _clang-format file in the project directory.

When using -style=file, clang-format for each input file will try to find the .clang-format file located in the closest parent directory of the input file. When the standard input is used, the search is started from the current directory.


无论我如何创建 .clang_format文件(我已经尝试过 clang-format -style=google -dump-config > .clang_format )或者我把它放在哪里,如果我执行 clang-format -style=file <file>它不格式化任何东西。
有人有同样的问题吗?
例如,如果我有一个文件 hello.cpp :
#include <stdio>

std::string s=" VERY BAD"
"FORMATTING";

int   main()   {
  std::cout<< "Hello world!"<<'\n';
  return 0;


}
如果我运行:
$ clang-format -style=mozilla -dump-config > .clang_format
即使我不编辑 .clang_format文件,然后
$ clang-format -style=file hello.cpp
我得到默认的 LLVM 格式样式而不是 Mozilla 样式:
#include <stdio>

std::string s = " VERY BAD"
                "FORMATTING";

int main() {
  std::cout << "Hello world!" << '\n';
  return 0;
}
但如果我跑 $ clang-format -style=mozilla hello.cpp然后我得到
#include <stdio>

std::string s = " VERY BAD"
                "FORMATTING";

int
main()
{
  std::cout << "Hello world!" << '\n';
  return 0;
}
如果我移动之前生成的 .clang_format,也会发生同样的情况在 hello.cpp 的父目录中目录。
我尝试过任何方法,但似乎我必须坚持使用预先配置的样式。
有同样问题的人吗?
我可以从 clang-format 中获得某种日志记录吗?
解决方案 :
文件名必须是 .clang-format ,不是 .clang_format !

最佳答案

我正在创建一个名称错误的配置文件。

它必须命名为 .clang-format ,不是 .clang_format .

关于c++ - clang-format -style=file 在 Ubuntu 18.04 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60398699/

相关文章:

c++ - 错误 C3017 : termination test in OpenMP 'for' statement has improper form

c++ - 为什么模板参数包必须在最后?

c - -lcs50 命令行参数在 clang 中有什么作用?

c - 在 Ubuntu 18.04 上编译 Python 3.7.4 时测试失败

c++ - 从 C++ 中定义的异常返回整数

c++ - 模板特化 GCC 的语法错误,但不是 MSVC

c++ - 数组类型的模板代码中如何计算 std::size_t

c++ - 什么时候可以/将在 C++ 中内联一个函数?可以强制执行内联行为吗?

Tensorflow 无法在 ubuntu 18.04 上加载动态库“libcudart.so.10.0”

python - 无法像使用 virtualenv 一样使用 venv 定义 python 包(版本)