]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/max-lines.md
de4ea0d94f2898fcee54f82eb2ae74d65eb5e19c
[pve-eslint.git] / eslint / docs / rules / max-lines.md
1 # enforce a maximum file length (max-lines)
2
3 Some people consider large files a code smell. Large files tend to do a lot of things and can make it hard following what's going. While there is not an objective maximum number of lines considered acceptable in a file, most people would agree it should not be in the thousands. Recommendations usually range from 100 to 500 lines.
4
5 ## Rule Details
6
7 This rule enforces a maximum number of lines per file, in order to aid in maintainability and reduce complexity.
8
9 Please note that most editors show an additional empty line at the end if the file ends with a line break. This rule does not count that extra line.
10
11 ## Options
12
13 This rule has a number or object option:
14
15 * `"max"` (default `300`) enforces a maximum number of lines in a file
16
17 * `"skipBlankLines": true` ignore lines made up purely of whitespace.
18
19 * `"skipComments": true` ignore lines containing just comments
20
21 ### code
22
23 Examples of **incorrect** code for this rule with a max value of `2`:
24
25 ```js
26 /*eslint max-lines: ["error", 2]*/
27 var a,
28 b,
29 c;
30 ```
31
32 ```js
33 /*eslint max-lines: ["error", 2]*/
34
35 var a,
36 b,c;
37 ```
38
39 ```js
40 /*eslint max-lines: ["error", 2]*/
41 // a comment
42 var a,
43 b,c;
44 ```
45
46 Examples of **correct** code for this rule with a max value of `2`:
47
48 ```js
49 /*eslint max-lines: ["error", 2]*/
50 var a,
51 b, c;
52 ```
53
54 ```js
55 /*eslint max-lines: ["error", 2]*/
56
57 var a, b, c;
58 ```
59
60 ```js
61 /*eslint max-lines: ["error", 2]*/
62 // a comment
63 var a, b, c;
64 ```
65
66 ### skipBlankLines
67
68 Examples of **incorrect** code for this rule with the `{ "skipBlankLines": true }` option:
69
70 ```js
71 /*eslint max-lines: ["error", {"max": 2, "skipBlankLines": true}]*/
72
73 var a,
74 b,
75 c;
76 ```
77
78 Examples of **correct** code for this rule with the `{ "skipBlankLines": true }` option:
79
80 ```js
81 /*eslint max-lines: ["error", {"max": 2, "skipBlankLines": true}]*/
82
83 var a,
84 b, c;
85 ```
86
87 ### skipComments
88
89 Examples of **incorrect** code for this rule with the `{ "skipComments": true }` option:
90
91 ```js
92 /*eslint max-lines: ["error", {"max": 2, "skipComments": true}]*/
93 // a comment
94 var a,
95 b,
96 c;
97 ```
98
99 Examples of **correct** code for this rule with the `{ "skipComments": true }` option:
100
101 ```js
102 /*eslint max-lines: ["error", {"max": 2, "skipComments": true}]*/
103 // a comment
104 var a,
105 b, c;
106 ```
107
108 ## When Not To Use It
109
110 You can turn this rule off if you are not concerned with the number of lines in your files.
111
112 ## Further reading
113
114 * [Software Module size and file size](https://web.archive.org/web/20160725154648/http://www.mind2b.com/component/content/article/24-software-module-size-and-file-size)
115
116 ## Related Rules
117
118 * [complexity](complexity.md)
119 * [max-depth](max-depth.md)
120 * [max-lines-per-function](max-lines-per-function.md)
121 * [max-nested-callbacks](max-nested-callbacks.md)
122 * [max-params](max-params.md)
123 * [max-statements](max-statements.md)
124
125 ## Compatibility
126
127 * **JSCS**: [maximumNumberOfLines](https://jscs-dev.github.io/rule/maximumNumberOfLines)