2017-05-30 71 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