我在 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/