【发布时间】:2021-01-02 16:53:02
【问题描述】:
在我的一个 Vue 项目中,Eslint 因任何错误(例如“字符串必须使用单引号”或“声明但从未使用的变量”)而开始破坏构建。格式错误也不会自动更正(尽管它们应该?)。我不知道这是什么时候发生的以及是什么原因造成的。可能在npm install之后。
我找到了多个通过将emitWarning: true 添加到 eslint 配置来解决问题的建议,但不幸的是,它对我不起作用。
在我看来,有时第一次构建尝试是成功的,并且只有在我更改代码中的某些内容、保存并重新启动服务器之后才会“检测到”错误并抛出错误。此外,eslint 似乎只关心目前在 VS Code 中实际打开的文件,如果我关闭文件并重新启动,eslint 不再关心那里的格式不正确。
这是我的.eslintrc.js 内容:
module.exports = {
root: true,
env: {
node: true,
"es6": true
},
extends: [
"plugin:vue/essential",
"@vue/standard"
],
rules: {
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
"indent": ["error", 4],
"semi": ["error", "always"],
"space-before-function-paren": ["error", "never"],
"quotes": ["error", "single"]
},
parserOptions: {
parser: "babel-eslint",
sourceType: "module",
ecmaVersion: 6,
emitWarning: true, // tried with and without this
emitError: false, // tried with and without this
failOnError: false, // tried with and without this
failOnWarning: false // tried with and without this
}
};
我的另一个 Vue 项目运行良好。我无法确定设置中的任何有意义的差异。
如何阻止 eslint 破坏构建?这里还有什么问题?如有任何帮助,我将不胜感激!
【问题讨论】: