prettier-check
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript
A CLI tool to verify that all files match Prettier code style during CI or testing. Version 2.0.0 requires Node >=4 and a peer dependency on prettier. It forwards all arguments to prettier, making it easy to integrate into npm test scripts. Compared to alternatives like lint-staged, prettier-check focuses solely on checking formatting without auto-fixing, ideal for pre-commit hooks or CI gates.
Common errors
error Error: Cannot find module 'prettier' ↓
cause prettier is not installed or not in node_modules.
fix
Run npm install --save-dev prettier
error prettier-check: No files to check ↓
cause Glob pattern did not match any files due to quoting or path issues.
fix
Double-check glob pattern and ensure files exist. Use quotes in npm scripts: 'src/**/*.js'
error SyntaxError: Unexpected token ... ↓
cause Using ES2015+ syntax (e.g., object spread) in Node <4 without transpilation.
fix
Update Node to >=4 or use a transpiler like Babel.
Warnings
gotcha prettier-check does not auto-fix files; it only returns exit code 1 on mismatch. ↓
fix Use prettier --write locally or in pre-commit hooks for auto-formatting.
breaking Version 2.0.0 changed behavior: it no longer lists non-conforming files; exit code only. ↓
fix For file listing, switch to prettier --list-different or use prettier-check@1.x.
deprecated prettier-check v1 is deprecated; upgrade to v2 for better compatibility with latest prettier. ↓
fix Update to prettier-check@2.0.0 but note changed behavior.
gotcha Glob patterns must be quoted in npm scripts to avoid shell expansion. ↓
fix Use double quotes: "prettier-check 'src/**/*.js'" or escape glob.
gotcha prettier must be installed as a dependency; global prettier may not be found. ↓
fix Ensure prettier is listed in devDependencies or installed globally.
Install
npm install prettier-check yarn add prettier-check pnpm add prettier-check Imports
- prettier-check (cli) wrong
npx prettier-check --check src/**/*.jscorrectnpx prettier-check --single-quote src/**/*.js - npm script usage wrong
"check-format": "prettier-check --list-different src/**/*.js"correct"check-format": "prettier-check src/**/*.js" - require or import wrong
const prettierCheck = require('prettier-check');correctnot applicable; CLI only
Quickstart
{
"scripts": {
"test": "prettier-check --single-quote --trailing-comma es5 src/**/*.js"
}
}