首页 > 解决方案 > 在某些函数**名称**上禁用 max-lines-per-function

问题描述

我正在使用 ESLintmax-lines-per-function来确保及时重构。我的 React 组件的render功能几乎总是超过我的 25 行,我想知道,除了添加禁用注释之外,是否有办法为某些函数名称(例如render)禁用 ESLint 规则?

标签: reactjseslint

解决方案


你可以使用 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"]
}

推荐阅读