Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable max-lines-per-function on certain function **names**

Tags:

reactjs

eslint

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)?

like image 754
Alexander Avatar asked Nov 18 '19 16:11

Alexander


People also ask

What does the maximum number of lines per function rule mean?

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:

How do I disable ESLint rules on a single line?

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>.

How do I disable a function from running at runtime?

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:

Is there a way to disable a function?

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


1 Answers

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"]
}
like image 71
Ben Avatar answered Oct 13 '22 19:10

Ben