简体   繁体   English

ESLint 不通知某些错误?

[英]ESLint not notifying about certain errors?

I'm trying to set up a React app with Gatsby, and for some reason the ESLint doesn't seem to be fully working properly.我正在尝试使用 Gatsby 设置 React 应用程序,但出于某种原因,ESLint 似乎无法完全正常工作。

I put the code const test = 4;我把代码const test = 4; and left the variable unused, which I would expect to throw an unused-variable error in ESLint, but it does not.并保留未使用的变量,我希望在 ESLint 中抛出未使用的变量错误,但事实并非如此。

I use VSCode.我使用 VSCode。

This is my eslintrc.json这是我的 eslintrc.json

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

These are the dependencies in my package.json这些是我的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"
  },

You need to add the rule in your eslintrc.json file:您需要在 eslintrc.json 文件中添加规则:

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

Of course, you can change the warning for your desired behavior.当然,您可以更改所需行为的警告。 You can check for further details in ESLint docs .您可以在ESLint 文档中查看更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM