简体   繁体   English

根据 .eslintrc 文件中的规则,eslint 不会在 VSCode 中给出错误

[英]eslint not giving errors in VSCode according to rules in .eslintrc file

I have installed eslint globally using npm and I have added my own .eslintrc file which contains following code:我已经使用 npm 全局安装了 eslint,并添加了我自己的 .eslintrc 文件,其中包含以下代码:

{
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true,
        "node": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true,
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "indent": [
            "error",
            "tab"
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    }
}

I have added following dev dependencies:我添加了以下开发依赖项:

"eslint": "3.19.0",
    "eslint-config-standard": "10.2.1",
    "eslint-plugin-import": "2.7.0",
    "eslint-plugin-markdown": "1.0.0-beta.6",
    "eslint-plugin-node": "5.1.1",
    "eslint-plugin-promise": "3.5.0",
    "eslint-plugin-standard": "3.0.1"

and also installed eslint-plugin-react in my react native project.并且还在我的本机项目中安装了eslint-plugin-react Still no indentation, semi colon, double quotes errors are shown, although parsing errors are shown.尽管显示了解析错误,但仍然没有显示缩进、分号、双引号错误。 PS eslint plugin is enabled in VScode. PS eslint 插件在 VScode 中启用。

Exact same thing happened to me.完全相同的事情发生在我身上。 And I found out the cause of this issue by looking at the Eslint log:我通过查看Eslint日志找到了这个问题的原因:

  1. Open Command Palette by Ctrl + Shift + P通过Ctrl + Shift + P打开命令面板
  2. Select Eslint: Show Output Channel选择Eslint: Show Output Channel

In my case, the output channel displayed this: Failed to load config "airbnb-base" to extend from. Referenced from: ...eslintrc.js就我而言,输出通道显示: Failed to load config "airbnb-base" to extend from. Referenced from: ...eslintrc.js Failed to load config "airbnb-base" to extend from. Referenced from: ...eslintrc.js

I just forgot to do npm install after adding the dev dependencies!我只是在添加开发依赖项后忘记执行npm install了!

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

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