【发布时间】:2020-09-28 07:36:06
【问题描述】:
我在 VSCode 的 Vue(Nuxt) 项目中使用 ESLint。当我保存时,我希望我的 ESLint 自动运行并自动为我修复所有警告。
这是我在 VSCode 中的 settings.json 文件:
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.validation.template": false,
"vetur.completion.scaffoldSnippetSources": {},
"vetur.completion.useScaffoldSnippets": false,
"vetur.format.defaultFormatter.html": "none",
"workbench.iconTheme": "material-icon-theme",
"git.autofetch": true,
"git.defaultCloneDirectory": "",
"gitlens.views.repositories.files.layout": "list",
"editor.tabSize": 2,
"editor.detectIndentation": false,
}
这是我的 .eslintrc.js 文件:
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
extends: [
"@nuxtjs",
"plugin:nuxt/recommended",
"../.eslintrc.js"
],
rules: {
//Add custom rules for the frontend here.
//Rules that are common for shared, frontend and backend should go in the parent file
"nuxt/no-cjs-in-config": "off",
},
}
链接的 ../.eslintrc.js 文件包含以下内容:
module.exports = {
parserOptions: {
parser: 'babel-eslint',
},
plugins: ['jest'],
rules: {
'prefer-const': 'off',
'comma-dangle': ['error', 'always-multiline'],
'prefer-template': 'error',
},
env: {
'jest/globals': true
}
}
编辑: 我已经打开了详细输出,我在输出中看到了这个:
(node:6832) UnhandledPromiseRejectionWarning: Error: Failed to load plugin 'import' declared in 'frontend\.eslintrc.js » @nuxtjs/eslint-config': Cannot find module 'eslint-plugin-import'
Require stack:
然后我运行yarn add eslint-plugin-import 并再次尝试,它仍然返回相同的错误。
【问题讨论】:
标签: visual-studio-code eslint vscode-settings lint