我有以下格式错误的文件,test.cpp
#include "maininclude.h"
int main() {
class SIMPLE smpl;
for (int i = 1; i < 100;
i++) {
printf("Printing %d", i); // Trying out different stuff...
getchar();
}
}
,我想在上面运行clang-format
。在运行这个之前,为了直观地看到要修改的地方,我运行clang-format -n test.cpp
。这将正确识别由于格式和终端输出错误而将被更改的位置:
test.cpp:3:13: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {
^
test.cpp:5:27: warning: code should be clang-formatted [-Wclang-format-violations]
for (int i = 1; i < 100;
^
test.cpp:6:9: warning: code should be clang-formatted [-Wclang-format-violations]
i++) {
^
test.cpp:7:64: warning: code should be clang-formatted [-Wclang-format-violations]
printf("Printing %d", i); // Trying out different stuff...
^
在运行clang-format test.cpp
时,我获得了正确格式化的文件的样子(此显示在终端上):
#include "maininclude.h"
int main() {
class SIMPLE smpl;
for (int i = 1; i < 100; i++) {
printf("Printing %d", i); // Trying out different stuff...
getchar();
}
}
然而,运行上述命令不会改变磁盘上实际的test.cpp
文件。是否有一个单独的选项/命令让clang-format
继续应用其更改并将文件保存在磁盘上?
Fromman clang-format
:
-i - Inplace edit <file>s, if specified.
使用-i
选项,即Inplace edit <file>s
。它将在适当的位置编辑文件。