2
尝试使用ESLint验证我的.js文件时,我收到了一个意外的词法声明(无案例声明)错误。ESLint/Nodejs:由于默认切换案例导致错误LINTING
c:\>eslint C:\modules\myFile.js
503:17 error Unexpected lexical declaration in case block no-case-declarations
以下是我的代码导致错误
switch (type) {
case String(type.match(/.*test.*/i)):
console.log('test')
break;
default:
console.log('error')
return err;
}
没有在VS代码显示了这个错误。 当我改变我的代码,如:
switch (type) {
case String(type.match(/.*test.*/i)):
console.log('test')
break;
/*default:
console.log('error')
return err;*/
}
所有的错误都消失了,所以我想它必须脱落默认情况下块。
以下是我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"
}
}
这可能是什么问题吗?据我了解,默认ESLint规则有默认情况下的规则,但不是 a 没有默认强制执行的规则。
感谢@Bradley:工作瞬间:) – BabyGroot