max-lines-per-function
Configuration
Enforce a maximum number of lines of code in a function.
Rule Details
Long functions are harder to follow than short ones. This rule reports any function whose body — including its declaration line and the closing brace — exceeds the configured line limit.
By default, the rule checks for a maximum of 50 lines per function. Comments and blank lines are counted, and IIFEs are skipped.
Examples of incorrect code for this rule with the default { "max": 50 }
option (function body shortened for brevity):
Examples of correct code for this rule with the default option:
Options
This rule accepts a number (the maximum allowed) or an object with the following properties:
max(default50): maximum number of lines a function may contain.skipBlankLines(defaultfalse): ignore lines made up purely of whitespace.skipComments(defaultfalse): ignore lines that contain only comments (a line with both code and a comment still counts).IIFEs(defaultfalse): whentrue, IIFEs are checked like other functions; whenfalse, they are skipped.
max
Examples of incorrect code for this rule with { "max": 2 }:
Examples of correct code for this rule with { "max": 3 }:
skipBlankLines
Examples of correct code for this rule with the above configuration:
skipComments
Examples of correct code for this rule with the above configuration:
IIFEs
Examples of incorrect code for this rule with the above configuration: