clang-format

ソースコード整形ツール

clang.llvm.org

インストール
$ sudo apt install clang-format   # Ubuntu
$ brew install clang-format       # macOS
使い方
基本スタイルとファイルを指定して整形する
$ clang-format -style=google dusty.cpp > purge.cpp

結果を上書きするには-i

$ clang-format -style=google -i overwrite.cpp
スタイルを細かく指定もできる
$ clang-format -style="{BasedOnStyle: Google, IndentWidth: 4, Standard: Cpp11}" dusty.cpp
スタイルファイルを作成して指定する

.clang-formatで作成し、プロジェクトディレクトリに配置する(と、そのディレクトリ以下にあるファイルで適用される)

$ clang-format -style=file dusty.cpp

スタイルファイルはyaml形式で書く。

---
BasedOnStyle: Google
IndentWidth: 4
Standard: Cpp11
...
Style Options 詳細

=> clang-format Style Optionsで。

zumaa.hateblo.jp