我使用 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
Run Code Online (Sandbox Code Playgroud)
或者
yarn add eslint-plugin-react-func -D
Run Code Online (Sandbox Code Playgroud)
在你的 .eslintrc.* 文件中
{
"rules": {
"react-func/max-lines-per-function": [
"warn",
{
"max": 25,
"skipBlankLines": true,
"skipComments": true,
"IIFEs": true
}
],
},
"plugins": ["react-func"]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1834 次 |
| 最近记录: |