Files
tldr/pages.zh/common/clang-format.md

739 B
Raw Blame History

clang-format

自动格式化 C/C++/Java/JavaScript/Objective-C/Protobuf/C# 代码。 更多信息:https://clang.llvm.org/docs/ClangFormat.html

  • 格式化文件并将结果打印到 stdout

clang-format {{path/to/file}}

  • 就地格式化文件:

clang-format -i {{path/to/file}}

  • 使用预定义编码风格格式化文件:

clang-format --style {{LLVM|GNU|Google|Chromium|Microsoft|Mozilla|WebKit}} {{path/to/file}}

  • 使用源文件的某个父目录中的 .clang-format 文件格式化文件:

clang-format --style=file {{path/to/file}}

  • 生成自定义的 .clang-format 文件:

clang-format --style {{LLVM|GNU|Google|Chromium|Microsoft|Mozilla|WebKit}} --dump-config > {{.clang-format}}