无法让 eslint 在 Atom 编辑器中工作

Unable to get eslint working in Atom Editor

此时我完全不知道如何让 ESLint 安装并使用 Atom 运行。所以我将 post 一步一步地进行,如果有人可以帮助完成这项工作,那将是非常棒的。

我已经卸载并重新安装了 Atom 插件,并禁用了除 Core 中的插件和 2 个 linters 之外的所有其他插件。

所有全局安装:

├── create-react-app@1.0.4
├── create-react-native-app@1.0.0
├── eslint@4.6.1
├── express-generator@4.14.1
├── json-server@0.9.5
├── mocha@3.2.0
├── nodemon@1.11.0
├── npm@3.10.10
├── pushstate-server@2.2.1
├── react-native-cli@2.0.1
├── react-vr-cli@0.3.5
├── webpack@2.2.1
├── webpack-dev-server@2.3.0
└── yarn@0.21.3

这些是我尝试让 eslint 在我的 Atom 项目中工作的步骤:

.eslintrc.json

{
  "extends": "airbnb"
}

package.json

{
  "name": "lint-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "eslint": "^4.6.1",
    "eslint-config-airbnb": "^15.1.0",
    "eslint-config-rallycoding": "^3.2.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-react": "^7.3.0"
  }
}

index.js

这只是一个文件,试图从 eslint

中获取某种类型的结果

错误

[Linter] 错误 运行ning ESLint(打开开发者控制台)

Configuration for rule "jsx-a11y/anchor-has-content" is invalid: Value "[object Object]" no (or more than one) schemas match.

Atom 开发人员控制台中未出现任何错误。但是 Atom 编辑器中的 Linter 也没有发生任何事情。我可以输入乱码但没有任何反应。

运行调试

调试结果:

Cannot find module 'eslint-config-airbnb'
Referenced from: /Users/user/development/lint-test/.eslintrc.json
Error: Cannot find module 'eslint-config-airbnb'
Referenced from: /Users/user/development/lint-test/.eslintrc.json
at ModuleResolver.resolve (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/util/module-resolver.js:74:19)
at resolve (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:515:25)
at load (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:584:26)
at configExtends.reduceRight.e (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:421:36)
at Array.reduceRight (native)
at applyExtends (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:403:28)
at loadFromDisk (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:556:22)
at Object.load (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:592:20)
at Config.getLocalConfigHierarchy (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config.js:226:44)
at Config.getConfigHierarchy (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config.js:180:43)

此时我假设它正在尝试从全局而不是本地读取

现在又没有任何反应,运行 再次调试

仍然找不到模块

此时我还在运行宁愿Cannot find module 'eslint-config-airbnb'

新本地package.json

"devDependencies": {
  "eslint": "^4.6.1",
  "eslint-config-airbnb": "^15.1.0",
  "eslint-plugin-import": "^2.7.0",
  "eslint-plugin-jsx-a11y": "^5.1.1",
  "eslint-plugin-react": "^7.3.0"
}

新全局模块

├── create-react-app@1.0.4
├── create-react-native-app@1.0.0
├── eslint@4.6.1
├── eslint-config-airbnb@15.1.0
├── eslint-plugin-import@2.7.0
├── UNMET PEER DEPENDENCY eslint-plugin-jsx-a11y@6.0.2
├── eslint-plugin-react@7.3.0
├── express-generator@4.14.1
├── install-peerdeps@1.1.3
├── json-server@0.9.5
├── mocha@3.2.0
├── nodemon@1.11.0
├── npm@3.10.10
├── pushstate-server@2.2.1
├── react-native-cli@2.0.1
├── react-vr-cli@0.3.5
├── webpack@2.2.1
├── webpack-dev-server@2.3.0
└── yarn@0.21.3

所以现在我可以 运行 DEBUG=eslint:* eslint . 并且可以得到一些结果。但是 Atom 中没有任何东西 运行。

结果:

/Users/user/development/lint-test/index.js
  1:1   error  Definition for rule 'jsx-a11y/href-no-hash' was not found  jsx-a11y/href-no-hash
  1:7   error  'config' is assigned a value but never used                no-unused-vars
  1:24  error  Unable to resolve path to module '../something'            import/no-unresolved
  1:39  error  Missing semicolon                                          semi

✖ 4 problems (4 errors, 0 warnings)
  1 error, 0 warnings potentially fixable with the `--fix` option.

在这一点上,我不知道如何让 Atom 真正与 eslint 一起工作...

没有深入研究问题并找到具体的失败点,我决定重新开始。

  • 删除全局节点模块。
  • 删除所有非核心 Atom 插件和主题。
  • 卸载 Atom。
  • 重新安装 Atom。
  • 仅安装 ESLint 和支持依赖项。

这样做我能够 运行 ESLint 没有任何问题。我对所有这些的假设是插件或主题中存在冲突。从那里安装我的核心工具插件是成功的。

取消选中 ATOM 的 linter-eslint 中的设置 "Use global ESLint installation" 将使其正确