Gin*_*pei 5 typescript reactjs eslint create-react-app
create-react-appv3.0.0已发布。它在内部支持TypeScript棉绒。(太好了!)我想我了解TSLint处于打开状态的情况,并计划用ESLint替换它,但现在还不行。
如何禁用掉毛步骤react-scripts start?
/* eslint-disable */ 其他人不是我要找的人。
更新:根据以下讨论,看起来没有办法操纵内部ESLint。因此,我的问题的答案将是“你不能”。
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
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
Gaj*_*jus 15
需要4处改动:
npm install @craco/craco --savecraco.config.js(在与 package.json 相同的文件夹中)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 文档。
.env如果它不存在,则在项目根目录中创建文件并将此行添加到其中
EXTEND_ESLINT=true
Run Code Online (Sandbox Code Playgroud)
.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
我的解决方法不弹出:
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)
{
"scripts": {
"eslint:disable": "REACT_APP_DEV_DISABLE_ESLINT=true",
"start": "npm run eslint:disable react-scripts start"
}
}
Run Code Online (Sandbox Code Playgroud)