Eslint在我的React应用程序中不起作用

我正在尝试将eslint添加到我的打字稿create-react-app应用程序中。 我正在使用Visual Studio代码。

我做到了:

  1. 以可视代码下载Eslint软件包
  2. 下载Eslint软件包
  3. 我安装了3个eslint插件
    "eslint:recommended","plugin:@typescript-eslint/recommended","plugin:react/recommended"
  1. 在应用程序的根文件夹中创建一个.eslintrc文件,如下所示:
{
  "plugins": [
    "react"
  ],"extends": [
    "eslint:recommended","plugin:react/recommended"
  ],"parserOptions": {
    "ecmaVersion": 7,"sourceType": "module","ecmaFeatures": {
        "jsx": true
    }
  },"env": {
    "browser": true,"node": true,"es6": true
  },"settings": {
    "import/resolver": {
      "node": {},"babel-module": {
        "root": ["./src"]
      }
    }
  }
}
  1. 启动eslint并重新启动vs代码

现在,我尝试做一些掉线的问题,例如尾随空格或不使用pascalCase,但是我从没有收到Eslint的警告,我只看到打字稿错误,但是从来没有看到过类似掉线的问题。

是否需要进行一些其他配置才能使其在我的工作空间中正常工作?

cc0734 回答:Eslint在我的React应用程序中不起作用

有类似的问题。原来我没有指定任何规则,所以从技术上讲Eslint可以工作,但是没有设置任何规则。首先,尝试扩展Airbnb规则:

public bool Remove(string name)

您还应该为文件指定TypeScript解析器:

"extends": [
    "eslint:recommended","plugin:@typescript-eslint/recommended","plugin:react/recommended","airbnb"
  ],

别忘了安装以上内容: module.exports = { parser: '@typescript-eslint/parser',... }

最后检查您的编辑器是否具有Eslint Extension设置!

本文链接:https://www.f2er.com/3120434.html

大家都在问