代码之家  ›  专栏  ›  技术社区  ›  Tryer

clang格式不会修改磁盘上的文件

  •  0
  • Tryer  · 技术社区  · 5 年前

    我有以下格式不正确的文件, 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 磁盘上的文件。是否有单独的选项/命令 叮当声格式 是否继续应用其更改并将文件保存到磁盘上?

    2 回复  |  直到 5 年前
        1
  •  2
  •   alfC    5 年前

    从…起 man clang-format

           -i                         - Inplace edit <file>s, if specified.
    
        2
  •  1
  •   Luis Guzman    5 年前

    使用 -i 选项,这意味着 Inplace edit <file>s . 我想它会在适当的地方编辑文件。