简体   繁体   English

尝试在 create-react-app 项目中扩展 ESLint 的问题

[英]Issues trying to extend ESLint in a create-react-app project

Create-react-app allows you to extend the ESLint config that comes with create-react-app: Create-react-app 允许你扩展 create-react-app 附带的 ESLint 配置:

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

However when I try to do this in my own project i just get this error ( Image of error )但是,当我尝试在自己的项目中执行此操作时,我只会收到此错误(错误图像

Error错误

Error: Cannot find module 'eslint-config-shared-config'

Command run命令运行

eslint --ignore-path.gitignore --ext.js,.ts,.tsx.

.eslintrc .eslintrc

{
  "extends": ["react-app", "shared-config"],
  "rules": {
    "additional-rule": "warn"
  },
  "overrides": [
    {
      "files": ["**/*.ts?(x)"],
      "rules": {
        "additional-typescript-only-rule": "warn"
      }
    }
  ]
}

A safe way to setup a base ESLint config file to build upon is by following the ESLint usage guide设置基本 ESLint 配置文件的安全方法是遵循ESLint 使用指南

$ npx eslint --init
# or
$ yarn run eslint --init

Like @jonrsharpe said, shared-config is just an example that cannot be used literally, the docs was trying to explain that you could use shared configurations.就像@jonrsharpe 所说, shared-config只是一个不能按字面意思使用的示例,文档试图解释您可以使用共享配置。

For example, if you add an ESLint plugin with a shared-config rule set, then you could use that as indicated by the example.例如,如果您添加一个带有shared-config规则集的 ESLint 插件,那么您可以按照示例所示使用它。

Difference between plugins and extends in ESLint ESLint 中插件和扩展的区别

EXTEND_ESLINT flag was removed in react-scripts v4 EXTEND_ESLINT标志在 react-scripts v4 中被移除

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

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