简体   繁体   中英

How can I tell Prettier to ignore a package.json file?

I am using prettier-standard because the project uses the standard for linting.

Following the prettier pre-commit hook example I am running prettier on commits. However I would like to ignore the package.json file. I tried adding package.json to a .prettierignore file but this did not work.

Code from the prettier pre-commit hook example that I am using in my package.json

{
  "scripts": {
    "precommit": "lint-staged"
  },
  "lint-staged": {
     "*.{js,json,css}": [
       "prettier --write",
       "git add"
     ]
  }
}

```

you can also use a .prettierignore file.

See the prettier project itself for a reference.

The limitation here is due to how lint-staged is used. I personally end up using a simple command (fast enough for me), without lint-staged (but still using husky+precommit).

prettier --write "**/*.{js,json,css,md}" !package.json

This command is in my package.json as a "format" script.

"precommit": "yarn format", // can be "npm run format"
"format": "prettier --write \"**/*.{js,json,css,md}\" \"!package.json\""

Please note the escaped quotes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM