【问题标题】:Eslint reporting in VSCode but not on the terminalEslint 在 VSCode 中报告,但不在终端上
【发布时间】:2018-05-28 21:00:06
【问题描述】:

我正在使用 es-lint VScode 扩展,它捕获了 5 个 linting 错误,但是当我从 package.json 运行 npm run lint 时,它只列出了 2 个错误。我想知道为什么终端没有输出所有 linting 错误,所以我可以在保存时使用esw --fix 修复它。

注意:我同时使用 prettier 和 airbnb 配置规则。

这是我的.eslintrc

{
  "extends": ["airbnb", "prettier"],
  "plugins": ["prettier"],
  "globals": { "document": false }
}

这里是pacjakge.json

 {
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "react-scripts": "1.0.17",
    "redux": "^3.7.2",
    "styled-components": "^2.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "lint": "eslint --fix ./src",
    "watch:lint": "node_modules/eslint-watch/bin/esw -w --fix"
  },
  "devDependencies": {
    "eslint": "^4.12.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-config-prettier": "^2.9.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-prettier": "^2.3.1",
    "eslint-plugin-react": "^7.5.1",
    "eslint-watch": "^3.1.3",
    "prettier": "^1.9.1"
  }

【问题讨论】:

    标签: eslint prettier eslintrc


    【解决方案1】:

    您在运行npm run lint 时使用--fix 选项,这意味着ESLint 只会显示无法自动修复的错误/警告。其他所有内容,它只会修复而不是抱怨。

    如果您希望它列出所有错误/警告,您可以从 NPM 脚本中删除 --fix,它会列出它找到的所有错误/警告(它将运行 eslint ./src)。稍后如果您也想修复错误,请运行npm run lint -- --fix,这会将-- 之后的所有内容直接传递给脚本,即运行eslint ./src --fix,它将正常工作。

    【讨论】:

      猜你喜欢
      • 2019-11-21
      • 2021-02-17
      • 1970-01-01
      • 2020-04-29
      • 2023-01-12
      • 1970-01-01
      • 2021-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多