特定のファイル、ディレクトリを除外して実行する方法
特定のファイル、ディレクトリを除外して実行するには.prettierignoreファイルで設定します。
$ 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? $ cat .prettierignore # srcディレクトリを除外する設定でファイルを作成 src $ npx prettier --check . # srcディレクトリは対象外となる Checking formatting... [warn] tsconfig.json [warn] Code style issues found in the above file(s). Forgot to run Prettier? $ cat .prettierignore # ワイルドカードでの指定も可能 src/index.* $ npx prettier --check . # src/index.cssとsrc/index.tsxは対象外となる Checking formatting... [warn] src/App.test.tsx [warn] src/App.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 --write . '!**/*.{ts,tsx}'