[英]How can I tell Prettier to ignore a package.json file?
I am using prettier-standard because the project uses the standard for linting. 我使用更漂亮的标准,因为该项目使用标签进行linting。
Following the prettier pre-commit hook example I am running prettier on commits. 在更漂亮的预提交钩子示例之后,我在提交时运行得更漂亮。 However I would like to ignore the package.json file.
但是我想忽略package.json文件。 I tried adding
package.json
to a .prettierignore file but this did not work. 我尝试将
package.json
添加到.prettierignore文件中,但这不起作用。
Code from the prettier pre-commit hook example that I am using in my package.json 来自我在package.json中使用的更漂亮的预提交钩子示例中的代码
{
"scripts": {
"precommit": "lint-staged"
},
"lint-staged": {
"*.{js,json,css}": [
"prettier --write",
"git add"
]
}
}
``` ```
you can also use a .prettierignore
file. 你也可以使用
.prettierignore
文件。
See the prettier project itself for a reference. 查看更漂亮的项目本身作为参考。
The limitation here is due to how lint-staged is used. 这里的限制是由于如何使用lint-staged。 I personally end up using a simple command (fast enough for me), without lint-staged (but still using husky+precommit).
我个人最终使用一个简单的命令(对我来说足够快),没有lint-staged(但仍然使用husky + precommit)。
prettier --write "**/*.{js,json,css,md}" !package.json
This command is in my package.json as a "format" script. 这个命令在我的package.json中作为“格式”脚本。
"precommit": "yarn format", // can be "npm run format"
"format": "prettier --write \"**/*.{js,json,css,md}\" \"!package.json\""
Please note the escaped quotes. 请注意转义的报价。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.