如何修复此错误消息 "Initialization error (Eslint). Unexpected Identifier"?

How do I fix this error message "Initialization error (Eslint). Unexpected Identifier"?

我有 EslintJSCS 设置以使用 airbnb js 风格指南[=41= 重新格式化一些代码库] 在 WebStorm 中。在过去的两天里,我一直在有效地使用这个设置,但是突然之间,WebStorm 开始抛出这个错误...

Problem with ESLint reformatting:index.js: Initialization error (ESLint). Unexpected identifier

我想我的 .eslintrc 可能有一些错误,但后来我使用相同的配置成功地重构了大约 150 个文件,然后才出现这个突然的错误。 在此之前,JSCS 编译器偶尔会抛出 "less than a minute timeout" 异常,但随后我会通过关闭并重新打开文件来解决此问题。 eslint 虽然似乎并不适合这个技巧。

这是我的.eslintrc配置

{
  "extends": "airbnb",
  "env": {
    "browser": true,
    "node": true
  },
  "globals": {
    "document": false
  },
  "rules": {
    "validateIndentation": 4,
    "func-names": [
      "error",
      "never"
    ],
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [
          ".js",
          ".jsx"
        ]
      }
    ],
    "jsx-a11y/label-has-for": [
      2,
      {
        "components": [
          "Label"
        ],
        "required": {
          "some": [
            "nesting",
            "id"
          ]
        },
        "allowChildren": false
      }
    ],
    "jsx-a11y/anchor-is-valid": [
      "error",
      {
        "components": [
          "Link"
        ],
        "specialLink": [
          "to",
          "hrefLeft",
          "hrefRight"
        ],
        "aspects": [
          "noHref",
          "invalidHref",
          "preferButton"
        ]
      }
    ]
  }
}

部分package.json

{
    "eslint": "^4.14.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-flowtype": "^2.40.1",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.5.1",
    "extract-text-webpack-plugin": "^3.0.2",
    "prop-types": "^15.6.0",
    "react": "^16.2.0",
    "react-dev-utils": "^4.2.1",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "react-router-dom": "^4.2.2",
  },
  "babel": {
    "presets": [
      "react-app",
      "flow"
    ]
  },
  "eslintConfig": {
    "extends": "react-app"
  }
}

有人能给我一些建议,告诉我如何解决这个问题吗?我怀疑它可能比 Eslint 更像是 WebStorm 错误。

PS:如果这个问题可能更适合 superuser,请原谅我。我只是觉得这里很可能有人遇到过同样的问题。

已解决 yarn upgrade


我尝试用新项目重现该问题失败了,使用相同的配置,eslintjscs 运行 成功。

然而,在非 js 文件上使用 WebStorm 上下文菜单命令 Apply ESlint Code Style Rules(在 .eslintrc 本身上测试)时,我得到了更详细的信息错误。

Error on attempt to find parent and base ESLint configuration files of '.eslintrc': [projectpath]\node_modules\lodash\lodash.js:386 '\u0149': ''n', '\u017f': 's',

我仔细检查了 lodash 包 node_modules 和 package.json,三重检查了设置配置(Eslint 和 JSCS),并确定我的设置与测试项目相同,没有错误。

运行 yarn upgrade lodash 救了我的头发。由于我已经是 运行 最新的 lodash,我认为 yarn 的解析和重建包成功了。

希望有人会发现这对在线的某个地方有帮助。

我在 phpstorm 中将此模式用于我的 eslint 配置,现在错误消失了,

{**/*,*}.{js,ts,jsx,tsx,html,vue},{!node_modules/*}