clang-formatフォーマットコード


clang-format is a tool to automatically format C/C++/Objective-C code, so that developers don't need to worry about style issues during code reviews.
インストール
$ sudo apt install clang-format

一般的なコマンドは次のとおりです.
  • プレビュー仕様後のコード
  • $ clang-format main.cc
  • は、元のファイル上で直接コード
  • を規範化する.
    $ clang-format -i main.cc
  • は指定コード仕様を表示し、デフォルトはLLVM
  • $ clang-format -style=google main.cc
  • 仕様をファイル
  • に保存する
     clang-format-6.0 -style=google -dump-config > .clang-format
  • 使用ファイル(ここのファイルfileは、パスを書くというわけではなく、fileを書くと自動的に.clang-formatファイルが見つかり、見つからない場合はデフォルトで使用されます)
  • clang-format -style=file -i src/xxx.c
    -iは、ソースファイルを直接変更することを意味します.
    フォルダの下のファイルを一緒にフォーマットする
    find ./har -iname "*.h"-o -iname "*.c"| xargs clang-format -style=file -i