此文长期整理配置eslint的坑点总结!
找不到自己项目中的.d.ts文件
场景:.d.ts文件是有,并且是能够编译过去的,只是eslint有警告
解决方法:安装eslint-plugin-import插件,并在.eslintrc.js文件中配置参数,添加指定文件后缀
1 2 3 4 5 6 7 8 9 10 |
module.exports = { // ...省略其它配置 "settings": { "import/resolver": { "node": { "extensions": [".js", ".jsx", ".ts", ".tsx", ".d.ts"], // 此处添加.d.ts } }, } } |
eslint警告loc的错误问题
TypeError: Cannot read property 'loc' of undefined
场景:在写变量const {} 写一半时就会在vscode提示出错误来,非常的烦锁
解决方法:在eslint配置中加入indent相关配置,如下
1 2 3 4 5 6 7 8 9 |
module.exports = { // ...省略其它配置 "rules": { { "indent": "off", "@typescript-eslint/indent": ["error", 2] } } } |
Parsing error: "parserOptions.project ***警告错误
解决办法一: tsconfig.json 识别警告错误的文件
1 2 3 4 5 6 7 8 9 10 |
{ "compilerOptions": { ・・・省略 }, "include": [ "./src", + "./.eslintrc.js", + "./vite.config.ts" ] } |
解决办法二:.eslintrc.js 文件内添加以下内容
1 |
ignorePatterns: ['.eslintrc.*', 'vite.config.*'], |