我正在創建一個新的 Vue 專案npm init vue@latest并選擇所有內容(Eslint with Prettier)
我正在使用以下設定
- 作業系統:Win11
- 節點:v17.4
- npm:v8.4
我設定了 lint-staged via npx mrm@2 lint-staged。出于測驗目的,我在src目錄中添加了一個新檔案
// calc.js
function
add
(numOne,
numTwo) {
return numOne
numTwo;
}
提交新檔案時,linter 按預期修復代碼樣式。但之后我必須手動洗掉生成的.eslintcache檔案。
較早的帖子說我應該添加
*.eslintcache
到.gitignore檔案。但是我將生成的.gitignore檔案與從 Vue CLI 生成的檔案進行了比較,兩者都沒有這一行。使用 Vue CLI 時,快取檔案不會出現。
那么還有其他解決方案還是我錯過了什么?
uj5u.com熱心網友回復:
該.eslintcache檔案是從 ESLint 的--cache標志創建的,該標志包含在以下默認 linter 命令中lint-staged:
// package.json
{
"lint-staged": { ??
"*.{vue,js,jsx,cjs,mjs}": "eslint --cache --fix",
"*.{js,css,md}": "prettier --write"
}
}
您可以洗掉該--cache標志:
// package.json
{
"lint-staged": {
"*.{vue,js,jsx,cjs,mjs}": "eslint --fix",
"*.{js,css,md}": "prettier --write"
}
}
...或使用--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"
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/426734.html
