禁用create-react-app提供的ESLint

Gin*_*pei 5 typescript reactjs eslint create-react-app

create-react-appv3.0.0已发布。它在内部支持TypeScript棉绒。(太好了!)我想我了解TSLint处于打开状态的情况,并计划用ESLint替换它,但现在还不行。

如何禁用掉毛步骤react-scripts start

/* eslint-disable */ 其他人不是我要找的人。

更新:根据以下讨论,看起来没有办法操纵内部ESLint。因此,我的问题的答案将是“你不能”

https://github.com/facebook/create-react-app/issues/808

kod*_*emi 58

您可以将 EXTEND_ESLINT 环境变量设置为true,例如在.env文件中:

EXTEND_ESLINT=true
Run Code Online (Sandbox Code Playgroud)

现在你可以在你的package.json文件中扩展 eslint 配置:

...
"eslintConfig": {
    "extends": "react-app",
    "rules": {
      "jsx-a11y/anchor-is-valid": "off"
    }
  },
...
Run Code Online (Sandbox Code Playgroud)

要禁用 eslint,您可以添加一个.eslintignore包含以下内容的文件:

*
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅文档:https : //create-react-app.dev/docs/setting-up-your-editor/#experimental-extending-the-eslint-config

  • 这不会禁用 eslint。这只是将 eslint 排除在所有文件之外。技术上不一样。 (2认同)

sar*_*ter 40

作为react-scriptsV4.0.2,您现在可以使用环境变量选择ESLint出来。您可以通过将其添加到您的.env文件中或在您的 package.json 文件中为您的脚本添加前缀来实现此目的。

例如在.env

DISABLE_ESLINT_PLUGIN=true
Run Code Online (Sandbox Code Playgroud)

或者在你的 package.json 中:

DISABLE_ESLINT_PLUGIN=true
Run Code Online (Sandbox Code Playgroud)

https://github.com/facebook/create-react-app/pull/10170

  • 如果您收到该错误(例如,如果您尝试从 Windows 运行它),请尝试以下操作: `"start": "set DISABLE_ESLINT_PLUGIN=true && react-scripts start",` (4认同)
  • 添加 package.json 时出现此错误 - 'DISABLE_ESLINT_PLUGIN' 未被识别为内部或外部命令。 (2认同)

Gaj*_*jus 15

您可以使用Craco禁用(并覆盖其他配置)。

需要4处改动:

  1. npm install @craco/craco --save
  2. 创建craco.config.js(在与 package.json 相同的文件夹中)
  3. 填充craco.config.js
module.exports = {
  eslint: {
    enable: false,
  },
};

Run Code Online (Sandbox Code Playgroud)

最后,在您的脚本中替换react-script为,即cracopackage.json

"scripts": {
  "build": "craco build",
  "start": "craco start",
}

Run Code Online (Sandbox Code Playgroud)

这将禁用 ESLint。有关如何扩展 ESLint 配置的示例,请参阅Craco 文档


Nit*_*hav 5

第1步

.env如果它不存在,则在项目根目录中创建文件并将此行添加到其中

EXTEND_ESLINT=true
Run Code Online (Sandbox Code Playgroud)

第2步

.eslintrc.js使用以下内容添加到您的项目根目录

module.exports = {
  "extends": ["react-app"],
  "rules": {
  },
  "overrides": [
    {
      "files": ["**/*.js?(x)"],
      "rules": {
// ******** add ignore rules here *********
        "react/no-unescaped-entities": "off",
        "react/display-name": "off",
        "react/prop-types": "off",
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

请注意该override > rules部分:添加带有“关闭”标志的规则以禁用它们。


小智 5

我的解决方法不弹出:

  1. 在.eslintrc.js中使用环境变量,如下所示:
module.exports = {
    "extends": process.env.REACT_APP_DEV_DISABLE_ESLINT ? [] : [
      "eslint:recommended",
      "plugin:import/errors",
      "plugin:import/warnings",
      "plugin:json/recommended",
      "plugin:@typescript-eslint/recommended",
      "plugin:jsx-a11y/recommended",
      "plugin:react/recommended",
    ],
    "rules": process.env.REACT_APP_DEV_DISABLE_ESLINT ? {} : {
      // ...rules for production CI
    }
}
Run Code Online (Sandbox Code Playgroud)
  1. 在package.json的启动脚本中设置变量:
{
      "scripts": {
          "eslint:disable": "REACT_APP_DEV_DISABLE_ESLINT=true",
          "start": "npm run eslint:disable  react-scripts start"
      }
}
Run Code Online (Sandbox Code Playgroud)