【问题标题】:ESLint doesn't lint ALL errors in command-lineESLint 不会 lint 命令行中的所有错误
【发布时间】:2016-07-02 15:29:15
【问题描述】:

我在我的项目中使用 eslint,.eslintrc 看起来像:

// http://eslint.org/docs/rules
{
  "parser": "babel-eslint",
  "env": {
    "browser": true,
    "node": true,
    "mocha": true
  },
  "plugins": [
    "react"
  ],
  "rules": {
    "strict": 0,
    "quotes": [2, "single"],
    "indent": [2, 4, {SwitchCase: 1}],
    "semi": [2, "always"],
    "no-underscore-dangle": 0,
    "no-unused-vars": 1,
    "no-unused-expressions": 0,
    "react/jsx-no-undef": 2,
    "react/jsx-boolean-value": 1,
    "react/jsx-sort-props": 0,
    "react/jsx-sort-prop-types": 0,
    "react/jsx-uses-react": 1,
    "react/jsx-uses-vars": 1,
    "react/no-did-mount-set-state": 0,
    "react/no-did-update-set-state": 1,
    "react/no-multi-comp": 0,
    "react/no-unknown-property": 1,
    "react/prop-types": 0,
    "react/react-in-jsx-scope": 1,
    "react/self-closing-comp": 1,
    "react/wrap-multilines": 1,
    "new-cap": 0,
    "no-extra-boolean-cast": 0,
    "yoda": 0,
    "no-empty": 0,
    "no-use-before-define": 0,
    "camelcase": 0
  },
  "globals": {
    "expect": true,
    "should": true,
    "FB": true,
    "gapi": true,
    "google": true,
    "customGoogleUtils": true,
    "encodeURIComonent": true,
    "decodeURIComonent": true
  }
}

我正在使用 Sublime Text 3 和必要的插件,它成功地 lints 代码:

但是当我在命令行中运行eslint ./src 时,它不会显示任何错误!。即使我将它指向文件夹 eslint ./src/path/to/file/with/errors 中有错误的特定文件。

我正在使用node_modules中的最新版本:

  • "babel-eslint": "^5.0.0"
  • "eslint": "^2.4.0"
  • "eslint-plugin-react": "^4.2.3"

更新

项目文件夹结构如下(我只linting/srcfodler):

有什么问题?

【问题讨论】:

  • 您可能想要检查从哪里调用eslint(在您的PATH 中的某个位置)以及它是否是最新的。 (which eslint 和 eslint --version)
  • 可以添加你项目的文件系统吗?
  • @BertrandMarron eslint --versionbash: eslint: command not found 但./node_modules/.bin/eslint --version v2.4.0
  • @Zamboney 更新了问题
  • 有趣的事实是,使用 airbnb-config-eslint 时会引发很多错误。虽然airbnb的配置不适合我,但我想扩展它。

标签: javascript node.js reactjs babeljs eslint


【解决方案1】:

我发现了一个问题 - .jsx 文件中存在 lint 错误,默认情况下 eslint ./src 仅验证 .js。

为了解决这个问题,我将 cli 命令更改如下 - eslint --ext .js --ext .jsx ./src。

【讨论】:

  • 没有更好的方法吗?喜欢在 .eslintrc 文件中做吗?
猜你喜欢
  • 2019-04-18
  • 1970-01-01
  • 2020-12-21
  • 2020-09-01
  • 2021-04-24
  • 2022-01-27
  • 1970-01-01
  • 1970-01-01
  • 2021-01-20
相关资源
最近更新 更多