在 @vue/cli 应用程序中,我收到错误 eslint 错误:
117:11 error 'resArray' is never reassigned. Use 'const' instead prefer-const
pointing at line :
let resArray = []
我通过在 package.json 中添加规则 Preferred-const = 0 禁用了此错误:
{
"name": "yt3",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.20.0-0",
"core-js": "^3.6.5",
"mitt": "^2.1.0",
"moment-timezone": "^0.5.31",
"node-sass": "^4.12.0",
"sass-loader": "^10.0.4",
"vee-validate": "^3.1.0",
"vue": "^3.0.0",
"vue-router": "^4.0.0-rc.1",
"vuex": "^4.0.0-rc.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "^3.0.0",
"@vue/eslint-config-standard": "^5.1.2",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^7.0.0-0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {
"semi": [
2,
"never"
],
"promise/param-names": [
0
],
"dot-notation": [
0
],
"no-trailing-spaces": [
0
],
"prefer-const": [
0
]
}
}
}
并运行命令:
yarn run serve
我预计最后一个值为 0 的条件将禁用此错误,但失败了。 哪个是有效的语法?
我有文件:.eslintrc.js,其中包含以下行:
module.exports = {
root: true,
env: {
node: true
},
extends: [
'plugin:vue/vue3-essential',
'@vue/standard'
],
parserOptions: {
parser: 'babel-eslint'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
}
我需要编辑它吗?它是如何工作的?
谢谢!
最佳答案
如果您已经有 .eslintrc.js
文件,我建议将所有 eslint 配置移到那里,以防止与 package.json
文件发生任何冲突。
您应该能够将 'prefer-const': 'off'
添加到您的规则
中以禁用该错误。
尽管如果您仅将 resArray
与数组操作一起使用,例如.push()
、.pop()
、.splice()
等,并且不会重新分配值,例如 resArray = []
那么您可以使用 const resArray = []
代替,而无需删除 prefer-const
规则。
关于vue.js - 为什么在vuejs应用程序中vuejs应用程序中的prefer-const规则没有被禁用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64642105/