我正在创建一个新的 Vue 项目npm init vue@latest并选择所有内容(Eslint 和 Prettier)
我正在使用以下设置
我通过设置lint-stagednpx mrm@2 lint-staged。出于测试目的,我在src目录中添加一个新文件
// calc.js
function
add
(numOne,
numTwo) {
return numOne +
numTwo;
}
Run Code Online (Sandbox Code Playgroud)
提交新文件时,linter 会按预期修复代码样式。但之后我必须手动删除生成的.eslintcache文件。
较旧的帖子说我应该添加
*.eslintcache
到.gitignore文件。但我将生成的.gitignore文件与 Vue CLI 生成的文件进行了比较,发现两者都没有这一行。使用 Vue CLI 时,不会出现缓存文件。
那么还有其他解决方案还是我错过了什么?
该.eslintcache文件是根据 ESLint 的--cache标志创建的,该标志包含在以下命令的默认 linter 命令中lint-staged:
// package.json
{
"lint-staged": {
"*.{vue,js,jsx,cjs,mjs}": "eslint --cache --fix",
"*.{js,css,md}": "prettier --write"
}
}
Run Code Online (Sandbox Code Playgroud)
您可以删除该--cache标志:
// package.json
{
"lint-staged": {
"*.{vue,js,jsx,cjs,mjs}": "eslint --fix",
"*.{js,css,md}": "prettier --write"
}
}
Run Code Online (Sandbox Code Playgroud)
--cache-location...或使用标志设置缓存文件位置(例如,指定node_modules/.cache):
// package.json
{
"lint-staged": {
"*.{vue,js,jsx,cjs,mjs}": "eslint --cache --fix --cache-location ./node_modules/.cache/.eslintcache",
"*.{js,css,md}": "prettier --write"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1087 次 |
| 最近记录: |