从Create React App扩展TypeScript ESLint配置

问题描述

我已按照本指南扩展了我的ESLint配置。

https://create-react-app.dev/docs/setting-up-your-editor/#experimental-extending-the-eslint-config

文档指出Note that any rules set to "error" will stop the project from building。我在.env文件所在的文件夹中添加EXTEND_ESLINT=true文件package.json

https://create-react-app.dev/docs/advanced-configuration/

添加文件后,即使使用package.json中的认值,我也停止从命令npm run build发出警告:

enter image description here

"eslintConfig": {
  "extends": "react-app"
},

如果我将.env文件设置为EXTEND_ESLINT=false,则警告会再次显示

enter image description here

首先这样做的原因是因为我想添加no-multiple-empty-lines规则,如下所示:

"eslintConfig": {
  "extends": [ "react-app" ],"rules": {
    "no-multiple-empty-lines": [
      "error",{
        "max": 1,"maxEOF": 0,"maxBOF": 0
      }
    ]
  }
},

https://eslint.org/docs/rules/no-multiple-empty-lines

我认为配置是正确的,因为当我添加此规则时,以下命令将显示预期结果:

npx eslint . --ext .js,.jsx,.ts,.tsx

更改配置之前:

enter image description here

更改配置后:

enter image description here

在读取.env文件时,它表示npm run build将按以下顺序读取文件.env.production.local,.env.production,.env.local,.env。由于我只有.env,因此应该选择它。文档还在EXTEND_ESLINT-You do not need to declare REACT_APP_ before the below variables as you would with custom environment variables.

上声明了这一点

https://create-react-app.dev/docs/adding-custom-environment-variables/#adding-development-environment-variables-in-env

我也已经阅读了该主题,但看不到错误之处:

How is ESLint integrated into Create React App?

如果我将scripts中的package.json部分编辑为"build": "set EXTEND_ESLINT=true && react-scripts build",,我将收到正常警告,但无论如何我添加的规则将不会执行。

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)