I'm using ESLint's max-lines-per-function
to make sure I refactor in time. My React components' render
function almost always exceed my 25 lines and I was wondering, besides adding a disable comment, if there was a way to disable an ESLint rule for certain function names (such as render
)?
This rule enforces a maximum number of lines per function, in order to aid in maintainability and reduce complexity. Why not use max-statements or other complexity measurement rules instead? Nested long method chains like the below example are often broken onto separate lines for readability:
Disable ESLint rules on a single line In some situations, you may need to disable some linter rules on a single line. The syntax for this is: // eslint-disable-line <rule1, rule2>.
In version 1.x, you can also use the disabledproperty of the function.jsonfile to tell the runtime not to trigger a function. This method only works for scripting languages such as C# script and JavaScript. The disabledproperty can be set to trueor to the name of an app setting:
While the application setting method is recommended for all languages and all runtime versions, there are several other ways to disable functions. These methods, which vary by language and runtime version, are maintained for backward compatibility. C# class libraries
You can use an ESLint plugin eslint-plugin-react-func. It also has a rule called max-lines-per-function
, but this rule will skip any function that contains JSX element
npm i eslint-plugin-react-func -D
or
yarn add eslint-plugin-react-func -D
In your .eslintrc.* file
{
"rules": {
"react-func/max-lines-per-function": [
"warn",
{
"max": 25,
"skipBlankLines": true,
"skipComments": true,
"IIFEs": true
}
],
},
"plugins": ["react-func"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With