【问题标题】:Eslint gives error: Configuration for rule "strict" is invalid: Value "error" is the wrong typeEslint 给出错误:规则“严格”的配置无效:值“错误”是错误的类型
【发布时间】:2017-01-24 08:29:55
【问题描述】:

我尝试通过以下选项使用 Eslint:

{
  "rules": {
    "indent": [
      2,
      2,
      {
        "SwitchCase": 1
      }
    ],
    "space-before-function-paren": [
      2,
      {
        "anonymous": "always",
        "named": "never"
      }
    ],
    "no-use-before-define": [
      2,
      "nofunc"
    ],
    // TODO: turn on later
    "comma-dangle": [
      0
    ],
    "prefer-template": 0
  },
  "env": {
    "node": true,
    "mocha": true
  },
  "extends": [
    "eslint:recommended",
    "airbnb/base"
  ]
}

我得到了错误:

错误:... ... /node_modules/eslint-config-airbnb-base/index.js: 规则“严格”的配置无效: 值“error”是错误的类型。

引用自:airbnb/base

我认为这个值:'error' 导致了错误。

eslint-config-airbnb-base/rules/strict.js

module.exports = {
  rules: {
    // babel inserts `'use strict';` for us
    strict: ['error', 'never']
  }
};

我该如何解决这个错误?

【问题讨论】:

    标签: gulp ecmascript-6 eslint


    【解决方案1】:

    Severity configuration strings"off""warn""error")是在 ESLint 的 2.3.0 版本中引入的。升级到该版本或更高版本应该可以解决您的问题。

    【讨论】:

      【解决方案2】:

      如果您的项目根目录中没有设置“rules.semi”的 eslint 资源文件.eslintrc.json,您也可能遇到此问题。

      这个示例资源文件可以修复错误

      $ cat .eslintrc.json 
      {
          "parserOptions": {
              "ecmaVersion": 6,
              "sourceType": "module",
              "ecmaFeatures": {
                  "jsx": true
              }
          },
          "rules": {
              "semi": "error"
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2021-02-23
        • 1970-01-01
        • 2016-06-20
        • 2020-09-03
        • 1970-01-01
        • 1970-01-01
        • 2013-08-10
        • 2014-08-08
        • 1970-01-01
        相关资源
        最近更新 更多