Some people consider large files a code smell. Large files tend to do a lot of things and can make following what's going on hard.
This rule enforces a maximum number of lines per file, in order to aid in maintainability and reduce complexity.
This rule has a number or object option:
-
"max"
(default100
) enforces a maximum number of lines in a file -
"skipBlankLines": true
ignore lines made up purely of whitespace. -
"skipComment": true
ignore lines containing just comments
Examples of incorrect code for this rule with a max value of 2
:
/*eslint max-lines: ["error", 2]*/
var a,
b,
c;
/*eslint max-lines: ["error", 2]*/
var a,
b,c;
/*eslint max-lines: ["error", 2]*/
// a comment
var a,
b,c;
Examples of correct code for this rule with a max value of 2
:
/*eslint max-lines: ["error", 2]*/
var a,
b, c;
/*eslint max-lines: ["error", 2]*/
var a, b, c;
/*eslint max-lines: ["error", 2]*/
// a comment
var a, b, c;
Examples of incorrect code for this rule with the { "skipBlankLines": true }
option:
/*eslint max-lines: ["error", 2, {"skipBlankLines": true}]*/
var a,
b,
c;
Examples of correct code for this rule with the { "skipBlankLines": true }
option:
/*eslint max-lines: ["error", 2, {"skipBlankLines": true}]*/
var a,
b, c;
Examples of incorrect code for this rule with the { "skipComments": true }
option:
/*eslint max-lines: ["error", 2, {"skipComments": true}]*/
// a comment
var a,
b,
c;
Examples of correct code for this rule with the { "skipComments": true }
option:
/*eslint max-lines: ["error", 2, {"skipComments": true}]*/
// a comment
var a,
b, c;
You can turn this rule off if you are not concerned with the number of lines in your files.