【问题标题】:ESLint not notifying about certain errors?ESLint 没有通知某些错误?
【发布时间】:2021-01-21 21:31:07
【问题描述】:

我正在尝试使用 Gatsby 设置 React 应用程序,但由于某种原因,ESLint 似乎无法完全正常工作。

我输入了代码const test = 4; 并没有使用变量,我希望这会在 ESLint 中引发未使用的变量错误,但事实并非如此。

我使用 VSCode。

这是我的 eslintrc.json

{
  "extends": ["airbnb", "prettier", "prettier/react"],
  "plugins": ["prettier"],
  "rules": {
    "prettier/prettier": "error"
  }
}

这些是我package.json中的依赖项

    "dependencies": {
    "@material-ui/core": "^4.11.0",
    "@material-ui/icons": "^4.9.1",
    "gatsby": "^2.24.67",
    "gatsby-cli": "^2.12.102",
    "gatsby-plugin-material-ui": "^2.1.10",
    "react": "^16.12.0",
    "react-dom": "^16.12.0"
  },
  "devDependencies": {
    "eslint": "^7.10.0",
    "eslint-config-airbnb": "^18.2.0",
    "eslint-config-prettier": "^6.12.0",
    "eslint-plugin-prettier": "^3.1.4",
    "prettier": "2.0.5"
  },

【问题讨论】:

  • @AllanChain 在执行npm run start 时,错误确实会出现在终端中,但不会出现在“问题”选项卡下的 VSCode 上

标签: json reactjs visual-studio-code gatsby eslint


【解决方案1】:

您需要在您的 eslintrc.json 文件中添加规则:

"rules":{
    "no-unused-vars": "warn",
}

当然,您可以将警告更改为您想要的行为。您可以在ESLint docs查看更多详细信息。

【讨论】:

    猜你喜欢
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    相关资源
    最近更新 更多