]>
Commit | Line | Data |
---|---|---|
8f9d1d4d DC |
1 | --- |
2 | title: max-lines | |
8f9d1d4d DC |
3 | rule_type: suggestion |
4 | related_rules: | |
5 | - complexity | |
6 | - max-depth | |
7 | - max-lines-per-function | |
8 | - max-nested-callbacks | |
9 | - max-params | |
10 | - max-statements | |
11 | further_reading: | |
12 | - https://web.archive.org/web/20160725154648/http://www.mind2b.com/component/content/article/24-software-module-size-and-file-size | |
13 | --- | |
14 | ||
eb39fafa DC |
15 | |
16 | 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. | |
17 | ||
18 | ## Rule Details | |
19 | ||
20 | This rule enforces a maximum number of lines per file, in order to aid in maintainability and reduce complexity. | |
21 | ||
6f036462 | 22 | 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. |
eb39fafa DC |
23 | |
24 | ## Options | |
25 | ||
26 | This rule has a number or object option: | |
27 | ||
28 | * `"max"` (default `300`) enforces a maximum number of lines in a file | |
29 | ||
30 | * `"skipBlankLines": true` ignore lines made up purely of whitespace. | |
31 | ||
32 | * `"skipComments": true` ignore lines containing just comments | |
33 | ||
5422a9cc | 34 | ### max |
eb39fafa DC |
35 | |
36 | Examples of **incorrect** code for this rule with a max value of `2`: | |
37 | ||
8f9d1d4d DC |
38 | ::: incorrect |
39 | ||
eb39fafa DC |
40 | ```js |
41 | /*eslint max-lines: ["error", 2]*/ | |
42 | var a, | |
43 | b, | |
44 | c; | |
45 | ``` | |
46 | ||
8f9d1d4d DC |
47 | ::: |
48 | ||
49 | ::: incorrect | |
50 | ||
eb39fafa DC |
51 | ```js |
52 | /*eslint max-lines: ["error", 2]*/ | |
53 | ||
54 | var a, | |
55 | b,c; | |
56 | ``` | |
57 | ||
8f9d1d4d DC |
58 | ::: |
59 | ||
60 | ::: incorrect | |
61 | ||
eb39fafa DC |
62 | ```js |
63 | /*eslint max-lines: ["error", 2]*/ | |
64 | // a comment | |
65 | var a, | |
66 | b,c; | |
67 | ``` | |
68 | ||
8f9d1d4d DC |
69 | ::: |
70 | ||
eb39fafa DC |
71 | Examples of **correct** code for this rule with a max value of `2`: |
72 | ||
8f9d1d4d DC |
73 | ::: correct |
74 | ||
eb39fafa DC |
75 | ```js |
76 | /*eslint max-lines: ["error", 2]*/ | |
77 | var a, | |
78 | b, c; | |
79 | ``` | |
80 | ||
8f9d1d4d DC |
81 | ::: |
82 | ||
83 | ::: correct | |
84 | ||
eb39fafa DC |
85 | ```js |
86 | /*eslint max-lines: ["error", 2]*/ | |
87 | ||
88 | var a, b, c; | |
89 | ``` | |
90 | ||
8f9d1d4d DC |
91 | ::: |
92 | ||
93 | ::: correct | |
94 | ||
eb39fafa DC |
95 | ```js |
96 | /*eslint max-lines: ["error", 2]*/ | |
97 | // a comment | |
98 | var a, b, c; | |
99 | ``` | |
100 | ||
8f9d1d4d DC |
101 | ::: |
102 | ||
eb39fafa DC |
103 | ### skipBlankLines |
104 | ||
105 | Examples of **incorrect** code for this rule with the `{ "skipBlankLines": true }` option: | |
106 | ||
8f9d1d4d DC |
107 | ::: incorrect |
108 | ||
eb39fafa DC |
109 | ```js |
110 | /*eslint max-lines: ["error", {"max": 2, "skipBlankLines": true}]*/ | |
111 | ||
112 | var a, | |
113 | b, | |
114 | c; | |
115 | ``` | |
116 | ||
8f9d1d4d DC |
117 | ::: |
118 | ||
eb39fafa DC |
119 | Examples of **correct** code for this rule with the `{ "skipBlankLines": true }` option: |
120 | ||
8f9d1d4d DC |
121 | ::: correct |
122 | ||
eb39fafa DC |
123 | ```js |
124 | /*eslint max-lines: ["error", {"max": 2, "skipBlankLines": true}]*/ | |
125 | ||
126 | var a, | |
127 | b, c; | |
128 | ``` | |
129 | ||
8f9d1d4d DC |
130 | ::: |
131 | ||
eb39fafa DC |
132 | ### skipComments |
133 | ||
134 | Examples of **incorrect** code for this rule with the `{ "skipComments": true }` option: | |
135 | ||
8f9d1d4d DC |
136 | ::: incorrect |
137 | ||
eb39fafa DC |
138 | ```js |
139 | /*eslint max-lines: ["error", {"max": 2, "skipComments": true}]*/ | |
140 | // a comment | |
141 | var a, | |
142 | b, | |
143 | c; | |
144 | ``` | |
145 | ||
8f9d1d4d DC |
146 | ::: |
147 | ||
eb39fafa DC |
148 | Examples of **correct** code for this rule with the `{ "skipComments": true }` option: |
149 | ||
8f9d1d4d DC |
150 | ::: correct |
151 | ||
eb39fafa DC |
152 | ```js |
153 | /*eslint max-lines: ["error", {"max": 2, "skipComments": true}]*/ | |
154 | // a comment | |
155 | var a, | |
156 | b, c; | |
157 | ``` | |
158 | ||
8f9d1d4d DC |
159 | ::: |
160 | ||
eb39fafa DC |
161 | ## When Not To Use It |
162 | ||
163 | You can turn this rule off if you are not concerned with the number of lines in your files. | |
164 | ||
eb39fafa DC |
165 | ## Compatibility |
166 | ||
167 | * **JSCS**: [maximumNumberOfLines](https://jscs-dev.github.io/rule/maximumNumberOfLines) |