While trying to validate my .js file using ESLint I received a an unexpected lexical declaration (no-case declarations) error.
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. 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.
Following is my 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.
via NodejsStarter
No comments:
Post a Comment