Skip to content

/commands/prettier/prettier-write-check

prettier --write and --check: format files from the command line

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
tool
Prettier
versions
Prettier 3.x
os
any

npx prettier . --write rewrites every supported file in the project with Prettier's formatting. npx prettier . --check only reports files that are not formatted and exits with status 1 if there are any, which is what you want in CI and pre-commit hooks.

Check, then write

bash
npm init -y >/dev/null
npm install --silent --no-audit --no-fund prettier@3 >/dev/null 2>&1
printf 'const greet = (name)=>{return "hi "+name}\n' > app.js
npx prettier . --check; echo "check exit status: $?"
npx prettier . --write
cat app.js
npx prettier . --check; echo "check exit status: $?"

Output

Checking formatting...
[warn] app.js
[warn] Code style issues found in the above file. Run Prettier with --write to fix.
check exit status: 1
app.js 26ms
package-lock.json 4ms (unchanged)
package.json 2ms (unchanged)
const greet = (name) => {
  return "hi " + name;
};
Checking formatting...
All matched files use Prettier code style!
check exit status: 0

Configure it

.prettierrc.json
{
  "singleQuote": true,
  "printWidth": 100,
  "trailingComma": "all"
}
.prettierignore
dist/
coverage/
package-lock.json

Prettier also reads .gitignore by default, so ignored build output is skipped.

Useful options

OptionEffect
--writeformat files in place
--checklist unformatted files; exit 1 if any
--list-differentprint only the names of unformatted files
--cacheskip unchanged files on later runs
--ignore-unknowndo not fail on files Prettier cannot parse
--config pathuse a specific config file

Sources