clang-format tool usage

clang-format tools cheat sheet, this tool aim at

  • keep code style consistent
  • auto check and format code

docs

https://clang.llvm.org/docs/ClangFormat.html

download

1
2
# mac
brew install llvm

usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# generate style file .clang-format, style can be [gnu, llvm, google, Mozilla, WebKit]
clang-format -style=WebKit -dump-config > .clang-format

# modify file directly
clang-format -i main.cpp

# modify git current staged changes
git clang-format

# modify most recently git commit
git clang-format HEAD~1

# in CI compare
clang-format --diff <before commit> <after commit>
Author

Helianthus

Posted on

2022-08-20

Updated on

2024-06-24

Licensed under