You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Restrict a maximum number of lines of code in a function.
17
+
/// Restrict the number of lines of code in a function.
18
18
///
19
+
/// This rule checks the number of lines in a function body and reports a diagnostic if it exceeds a specified limit.
19
20
/// Some people consider large functions a code smell. Large functions tend to do a lot of things and can make it hard following what’s going on. Many coding style guides dictate a limit of the number of lines that a function can comprise of. This rule can help enforce that style.
20
21
///
21
-
/// ## Options
22
-
///
23
-
/// The rule supports the following options:
22
+
/// ## Examples
24
23
///
24
+
/// When maximum number of lines is set to `2` with the following option, the following code will be considered invalid:
25
25
/// ```json,options
26
26
/// {
27
27
/// "options": {
28
-
/// "max": 4,
29
-
/// "skipBlankLines": true,
30
-
/// "iifes": true
28
+
/// "maxLines": 2
31
29
/// }
32
30
/// }
33
31
/// ```
34
32
///
35
-
/// - `max` (positive integer, default: 50): The maximum number of lines allowed in a function.
36
-
/// - `skip_blank_lines` (bool, default: false): A boolean value which indicates whether blank lines are counted or not.
37
-
/// - `iifes` (bool, default: false): A boolean value which indicates whether IIFEs (Immediately Invoked Function Expression) are checked or not.
38
-
///
39
-
/// ## Examples
40
-
///
41
33
/// ### Invalid
42
34
///
43
35
/// ```js,expect_diagnostic,use_options
@@ -51,7 +43,6 @@ declare_lint_rule! {
51
43
/// ```js,expect_diagnostic,use_options
52
44
/// const bar = () => {
53
45
/// const x = 0;
54
-
///
55
46
/// const y = 1;
56
47
/// const z = 2;
57
48
/// };
@@ -85,7 +76,6 @@ declare_lint_rule! {
85
76
///
86
77
/// const bar = () => {
87
78
/// const x = 0;
88
-
///
89
79
/// const y = 1;
90
80
/// };
91
81
///
@@ -102,6 +92,89 @@ declare_lint_rule! {
102
92
/// })();
103
93
/// ```
104
94
///
95
+
/// ## Options
96
+
///
97
+
/// The rule supports the following options:
98
+
///
99
+
/// ```json
100
+
/// {
101
+
/// "options": {
102
+
/// "maxLines": 50,
103
+
/// "skipBlankLines": false,
104
+
/// "skipIifes": false
105
+
/// }
106
+
/// }
107
+
/// ```
108
+
///
109
+
/// ### maxLines
110
+
///
111
+
/// This option sets the maximum number of lines allowed in a function body.
112
+
/// If the function body exceeds this limit, a diagnostic will be reported.
113
+
///
114
+
/// Default: `50`
115
+
///
116
+
/// When `maxLines: 2`, the following function will be considered invalid:
117
+
/// ```json,options
118
+
/// {
119
+
/// "options": {
120
+
/// "maxLines": 2
121
+
/// }
122
+
/// }
123
+
/// ```
124
+
/// ```js,expect_diagnostic,use_options
125
+
/// function example() {
126
+
/// const a = 1; // 1
127
+
/// const b = 2; // 2
128
+
/// const c = 3; // 3
129
+
/// };
130
+
/// ```
131
+
///
132
+
/// ### skipBlankLines
133
+
/// When this options is set to `true`, blank lines in the function body are not counted towards the maximum line limit.
134
+
/// This means that only lines with actual code or comments will be counted.
135
+
///
136
+
/// Default: `false`
137
+
///
138
+
/// When `maxLines: 2` and `skipBlankLines: true`, the following function will be considered valid:
139
+
/// ```json,options
140
+
/// {
141
+
/// "options": {
142
+
/// "maxLines": 2,
143
+
/// "skipBlankLines": true
144
+
/// }
145
+
/// }
146
+
/// ```
147
+
/// ```js,use_options
148
+
/// function example() {
149
+
/// const a = 1; // 1
150
+
/// // not counted
151
+
/// const b = 2; // 2
152
+
/// // not counted
153
+
/// };
154
+
/// ```
155
+
///
156
+
/// ### skipIifes
157
+
/// When this option is set to `true`, Immediately Invoked Function Expressions (IIFEs) are not checked for the maximum line limit.
158
+
///
159
+
/// Default: `false`
160
+
///
161
+
/// When `maxLines: 2` and `skipIifes: true`, the following IIFE will be considered valid even though its body has 3 lines:
162
+
/// ```json,options
163
+
/// {
164
+
/// "options": {
165
+
/// "maxLines": 2,
166
+
/// "skipIifes": true
167
+
/// }
168
+
/// }
169
+
/// ```
170
+
/// ```js,use_options
171
+
/// (() => {
172
+
/// const a = 1; // 1
173
+
/// const b = 2; // 2
174
+
/// const c = 3; // 3
175
+
/// })();
176
+
/// ```
177
+
///
105
178
pubNoExcessiveLinesPerFunction{
106
179
version:"2.0.0",
107
180
name:"noExcessiveLinesPerFunction",
@@ -123,30 +196,45 @@ impl Rule for NoExcessiveLinesPerFunction {
0 commit comments