LoginSignup
1
0

More than 1 year has passed since last update.

clang-format コマンドを効率よく多数のファイルへ一括で施す

Posted at

記事内容

clang-format コマンドをあるディレクトリ以下の特定ファイルに対して効率よく施すコマンドの紹介。

執筆同期

本内容に関して、ググっても分かりやすい例が無かった。

コマンド例

find bench include src test -name *.c -o -name *.cc -o -name *.cpp -o -name *.h -o -name *.hh -o -name *.hpp | xargs clang-format -i -style=file --verbose

find の後に、対象となるディレクトリを指定する。これは複数でも良い。
そのあとに -name *.c などを記述する。これは名前の末尾が .c であることを意味する。
-o で -name *.hogehoge みたいなものを論理和として併記できる。コマンド例では c / c++ 系のソース・ヘッダー拡張子を列挙している。
| xargs で find で出てくる結果を clang-format コマンドに渡している。
-i は in-place update. -style=file はフォーマットをかけるファイルの親ディレクトリのうちの一つにある .clang-format をフォーマット指定として利用する。
--verbose でどのファイルが正常に処理されたか出力される。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0