[英]Is there a way to change the eslint of the webpack for the create-react-app without ejecting
我想在不弹出的情况下更改反应应用程序的 eslint 规则。
We can add new ESLint rules by following just 3 simple steps.我们可以通过以下 3 个简单步骤添加新的 ESLint 规则。
Create .eslintrc.js under the src folder of the your project.在项目的 src 文件夹下创建 .eslintrc.js。
Add the following lines in the file:在文件中添加以下几行:
module.exports = { "extends": "react-app", "rules" : { "indent": ["error", 4] // A custom style-related rule for example // More custom rules here } } module.exports = { "extends": "react-app", "rules" : { "indent": ["error", 4] // 例如自定义样式相关规则 // 此处有更多自定义规则 } }
This way, we will be telling our IDE to extend the base ESLint rules provided by the create-react-app and then follow some rules defined by us.这样,我们将告诉我们的 IDE 扩展 create-react-app 提供的基本 ESLint 规则,然后遵循我们定义的一些规则。
In your package.json
, add the following script:在您的
package.json
,添加以下脚本:
"lint:fix": "eslint src/**/*.js --fix", "lint:fix": "eslint src/**/*.js --fix",
This is mainly for CLI and CI/CD environment.这主要是针对 CLI 和 CI/CD 环境的。
Now default setup in most of the IDEs are that they would read the configuration from src/.eslintrc.js.现在大多数 IDE 的默认设置是它们将从 src/.eslintrc.js 读取配置。 Hence you should now see errors/warnings from your custom eslintrc file on your IDE as well
因此,您现在也应该在 IDE 上看到来自自定义 eslintrc 文件的错误/警告
Src - http://rahulgaba.com/front-end/2019/02/17/Use-custom-eslint-config-in-create-react-app-using-three-simple-steps-No-external-dependencies.html Src - http://rahulgaba.com/front-end/2019/02/17/Use-custom-eslint-config-in-create-react-app-using-three-simple-steps-No-external-dependencies。 html
Add an .eslintrc
file to the root of your project and in that extend the eslint-config-react-app
and add your rules/overrides, eg将
.eslintrc
文件添加到项目的根目录,并在其中扩展eslint-config-react-app
并添加您的规则/覆盖,例如
// .eslintrc
{
"extends": "react-app",
"rules": {
// enable additional rules or override from react-app
"indent": ["error", 4],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.