]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/max-statements.md
first commit
[pve-eslint.git] / eslint / docs / rules / max-statements.md
1 # enforce a maximum number of statements allowed in function blocks (max-statements)
2
3 The `max-statements` rule allows you to specify the maximum number of statements allowed in a function.
4
5 ```js
6 function foo() {
7 var bar = 1; // one statement
8 var baz = 2; // two statements
9 var qux = 3; // three statements
10 }
11 ```
12
13 ## Rule Details
14
15 This rule enforces a maximum number of statements allowed in function blocks.
16
17 ## Options
18
19 This rule has a number or object option:
20
21 * `"max"` (default `10`) enforces a maximum number of statements allows in function blocks
22
23 **Deprecated:** The object property `maximum` is deprecated; please use the object property `max` instead.
24
25 This rule has an object option:
26
27 * `"ignoreTopLevelFunctions": true` ignores top-level functions
28
29 ### max
30
31 Examples of **incorrect** code for this rule with the default `{ "max": 10 }` option:
32
33 ```js
34 /*eslint max-statements: ["error", 10]*/
35 /*eslint-env es6*/
36
37 function foo() {
38 var foo1 = 1;
39 var foo2 = 2;
40 var foo3 = 3;
41 var foo4 = 4;
42 var foo5 = 5;
43 var foo6 = 6;
44 var foo7 = 7;
45 var foo8 = 8;
46 var foo9 = 9;
47 var foo10 = 10;
48
49 var foo11 = 11; // Too many.
50 }
51
52 let foo = () => {
53 var foo1 = 1;
54 var foo2 = 2;
55 var foo3 = 3;
56 var foo4 = 4;
57 var foo5 = 5;
58 var foo6 = 6;
59 var foo7 = 7;
60 var foo8 = 8;
61 var foo9 = 9;
62 var foo10 = 10;
63
64 var foo11 = 11; // Too many.
65 };
66 ```
67
68 Examples of **correct** code for this rule with the default `{ "max": 10 }` option:
69
70 ```js
71 /*eslint max-statements: ["error", 10]*/
72 /*eslint-env es6*/
73
74 function foo() {
75 var foo1 = 1;
76 var foo2 = 2;
77 var foo3 = 3;
78 var foo4 = 4;
79 var foo5 = 5;
80 var foo6 = 6;
81 var foo7 = 7;
82 var foo8 = 8;
83 var foo9 = 9;
84 var foo10 = 10;
85 return function () {
86
87 // The number of statements in the inner function does not count toward the
88 // statement maximum.
89
90 return 42;
91 };
92 }
93
94 let foo = () => {
95 var foo1 = 1;
96 var foo2 = 2;
97 var foo3 = 3;
98 var foo4 = 4;
99 var foo5 = 5;
100 var foo6 = 6;
101 var foo7 = 7;
102 var foo8 = 8;
103 var foo9 = 9;
104 var foo10 = 10;
105 return function () {
106
107 // The number of statements in the inner function does not count toward the
108 // statement maximum.
109
110 return 42;
111 };
112 }
113 ```
114
115 ### ignoreTopLevelFunctions
116
117 Examples of additional **correct** code for this rule with the `{ "max": 10 }, { "ignoreTopLevelFunctions": true }` options:
118
119 ```js
120 /*eslint max-statements: ["error", 10, { "ignoreTopLevelFunctions": true }]*/
121
122 function foo() {
123 var foo1 = 1;
124 var foo2 = 2;
125 var foo3 = 3;
126 var foo4 = 4;
127 var foo5 = 5;
128 var foo6 = 6;
129 var foo7 = 7;
130 var foo8 = 8;
131 var foo9 = 9;
132 var foo10 = 10;
133 var foo11 = 11;
134 }
135 ```
136
137 ## Related Rules
138
139 * [complexity](complexity.md)
140 * [max-depth](max-depth.md)
141 * [max-len](max-len.md)
142 * [max-lines](max-lines.md)
143 * [max-lines-per-function](max-lines-per-function.md)
144 * [max-nested-callbacks](max-nested-callbacks.md)
145 * [max-params](max-params.md)