Prettier:フォーマットは実行せずにフォーマット済みかどうかを確認する方法

スポンサーリンク

フォーマットは実行せずにフォーマット済みかどうかを確認する方法

フォーマットは実行せずにフォーマット済みかどうかを確認するには--checkオプション、--list-differentオプション(Pipe処理がしやすいようにファイルパスのみ表示)を使用します。

 

$ npx prettier --check .  # 未フォーマットのファイルのパスが表示される
Checking formatting...
[warn] src/App.test.tsx
[warn] src/App.tsx
[warn] src/index.css
[warn] src/index.tsx
[warn] src/reportWebVitals.ts
[warn] src/setupTests.ts
[warn] tsconfig.json
[warn] Code style issues found in the above file(s). Forgot to run Prettier?

$ npx prettier --list-different .  # --list-diffrentの場合はPipe処理がしやすいようにファイルパスのみ表示
src/App.test.tsx
src/App.tsx
src/index.css
src/index.tsx
src/reportWebVitals.ts
src/setupTests.ts
tsconfig.json
$ npx prettier --write .  # フォーマット実行

$ npx prettier --check .  # すべてフォーマット済みというメッセージが表示される
Checking formatting...
All matched files use Prettier code style!