[英]ESLint/Nodejs: Error linting due to default switch case
While trying to validate my .js file using ESLint I received a an unexpected lexical declaration (no-case declarations) error. 在尝试使用ESLint验证我的.js文件时,收到一个意外的词汇声明(无大小写声明)错误。
c:\>eslint C:\modules\myFile.js
503:17 error Unexpected lexical declaration in case block no-case-declarations
Following is my code that is causing the error 以下是导致错误的我的代码
switch (type) {
case String(type.match(/.*test.*/i)):
console.log('test')
break;
default:
console.log('error')
return err;
}
There is no error shown in vs-code for this. vs代码中没有显示此错误。 When i transform my code like:
当我像这样转换我的代码时:
switch (type) {
case String(type.match(/.*test.*/i)):
console.log('test')
break;
/*default:
console.log('error')
return err;*/
}
all errors disappear so I am thinking it must be coming off the default case block. 所有错误都消失了,所以我认为它一定来自默认的case块。
Following is my esLint.rc: 以下是我的esLint.rc:
{
"root": true,
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "script"
},
"env": {
"node": true,
"browser": false
},
"extends": "eslint:recommended",
"rules": {
"semi": ["error", "always"],
"indent": ["error", 4, {
"VariableDeclarator": 2,
"SwitchCase": 1,
"MemberExpression": 1,
"ArrayExpression": "first"
}],
"no-mixed-requires": "off",
"no-restricted-imports": "off",
"no-undef":"off",
"no-console":2,
"no-trailing-spaces": "error",
"no-unused-vars": "warn"
}
}
What could be the issue here? 这里可能是什么问题? As far as i read, the default ESLint rules have a default-case rule but not a no-default-enforced rule.
据我所知,默认的ESLint规则具有默认情况下的规则,但没有 无默认值的规则。
This is a tricky one cause it's not quite what you think. 这是一个棘手的原因,因为它与您的想法不完全相同。 The default not having {...} is the problem.
默认情况下没有{...}是问题所在。 So changing default: to default: { ... } will fix this.
因此,将default:更改为default:{...}将解决此问题。 If you want to turn it off, you'll have to remove an extension in eslint.
如果要关闭它,则必须删除eslint中的扩展名。
Specifically, this is being produced by the "extends" : "eslint:recommended" 具体来说,这是由“扩展”产生的:“ eslint:recommended”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.