2017-05-30 42 views
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 没有默认强制执行的规则。

回答

3

这是一个棘手的问题,因为它并不完全符合您的想法。没有{...}的默认值是问题。所以改变默认值:默认:{...}将会解决这个问题。如果你想关闭它,你必须在eslint中删除一个扩展名。

具体地说,这是由 “扩展” 制备: “eslint:推荐”

More information here

+0

感谢@Bradley:工作瞬间:) – BabyGroot

相关问题