reactjs - 在某些函数**名称**上禁用 max-lines-per-function
问题描述
我正在使用 ESLintmax-lines-per-function
来确保及时重构。我的 React 组件的render
功能几乎总是超过我的 25 行,我想知道,除了添加禁用注释之外,是否有办法为某些函数名称(例如render
)禁用 ESLint 规则?
解决方案
你可以使用 ESLint 插件eslint-plugin-react-func。它还有一个叫做 的规则max-lines-per-function
,但是这个规则会跳过任何包含 JSX 元素的函数
npm i eslint-plugin-react-func -D
或者
yarn add eslint-plugin-react-func -D
在您的 .eslintrc.* 文件中
{
"rules": {
"react-func/max-lines-per-function": [
"warn",
{
"max": 25,
"skipBlankLines": true,
"skipComments": true,
"IIFEs": true
}
],
},
"plugins": ["react-func"]
}
推荐阅读
- c# - 在 ASP.NET Core 3 的新浏览器窗口中打开 PDF 文件
- sql - SQL 查询从可变日期找出一周的非周末(周一至周五)日期
- odoo - 如何在 Odoo 13 中使用 many2one 为字段创建记录?
- reactjs - Material-UI 按钮需要单击 3 次才能呈现菜单
- python - 使用 selenium xpath 定位元素
- r - 在R中的循环中使用字符串作为对象名称
- oracle11g - 如何将子查询结果合并到每行另一个子查询的结果?
- python - 如何使用ansible为来自python dict的主机设置具有不同计划时间的cronjobs?
- python - 使用 selenium 抓取链接(href)的问题;href="#"
- javascript - 在graphQL中,如果我发送太多查询有时会出现graphql网络错误:响应不成功:收到状态码400我该如何解决?