@@ -87,11 +87,11 @@ declare_oxc_lint!(
87
87
///
88
88
/// ```js
89
89
/// switch(foo) {
90
- /// case 1:
91
- /// doSomething();
90
+ /// case 1:
91
+ /// doSomething();
92
92
///
93
93
/// case 2:
94
- /// doSomethingElse();
94
+ /// doSomethingElse();
95
95
/// }
96
96
/// ```
97
97
///
@@ -101,12 +101,12 @@ declare_oxc_lint!(
101
101
///
102
102
/// ```js
103
103
/// switch(foo) {
104
- /// case 1:
105
- /// doSomething();
106
- /// break;
104
+ /// case 1:
105
+ /// doSomething();
106
+ /// break;
107
107
///
108
- /// case 2:
109
- /// doSomethingElse();
108
+ /// case 2:
109
+ /// doSomethingElse();
110
110
/// }
111
111
/// ```
112
112
///
@@ -118,41 +118,41 @@ declare_oxc_lint!(
118
118
///
119
119
/// ```js
120
120
/// switch(foo) {
121
- /// case 1:
122
- /// doSomething();
123
- /// // falls through
121
+ /// case 1:
122
+ /// doSomething();
123
+ /// // falls through
124
124
///
125
- /// case 2:
126
- /// doSomethingElse();
125
+ /// case 2:
126
+ /// doSomethingElse();
127
127
/// }
128
128
///
129
129
/// switch(foo) {
130
- /// case 1:
131
- /// doSomething();
132
- /// // fall through
130
+ /// case 1:
131
+ /// doSomething();
132
+ /// // fall through
133
133
///
134
- /// case 2:
135
- /// doSomethingElse();
134
+ /// case 2:
135
+ /// doSomethingElse();
136
136
/// }
137
137
///
138
138
/// switch(foo) {
139
- /// case 1:
140
- /// doSomething();
141
- /// // fallsthrough
139
+ /// case 1:
140
+ /// doSomething();
141
+ /// // fallsthrough
142
142
///
143
- /// case 2:
144
- /// doSomethingElse();
143
+ /// case 2:
144
+ /// doSomethingElse();
145
145
/// }
146
146
///
147
147
/// switch(foo) {
148
- /// case 1: {
149
- /// doSomething();
150
- /// // falls through
151
- /// }
152
- ///
153
- /// case 2: {
154
- /// doSomethingElse();
155
- /// }
148
+ /// case 1: {
149
+ /// doSomething();
150
+ /// // falls through
151
+ /// }
152
+ ///
153
+ /// case 2: {
154
+ /// doSomethingElse();
155
+ /// }
156
156
/// }
157
157
/// ```
158
158
///
@@ -164,79 +164,75 @@ declare_oxc_lint!(
164
164
///
165
165
/// Examples of **incorrect** code for this rule:
166
166
/// ```js
167
- /// /*oxlint no-fallthrough: "error"*/
168
- ///
169
167
/// switch(foo) {
170
- /// case 1:
171
- /// doSomething();
168
+ /// case 1:
169
+ /// doSomething();
172
170
///
173
- /// case 2:
174
- /// doSomething();
171
+ /// case 2:
172
+ /// doSomething();
175
173
/// }
176
174
/// ```
177
175
///
178
176
/// Examples of **correct** code for this rule:
179
177
/// ```js
180
- /// /*oxlint no-fallthrough: "error"*/
181
- ///
182
178
/// switch(foo) {
183
- /// case 1:
184
- /// doSomething();
185
- /// break;
179
+ /// case 1:
180
+ /// doSomething();
181
+ /// break;
186
182
///
187
- /// case 2:
188
- /// doSomething();
183
+ /// case 2:
184
+ /// doSomething();
189
185
/// }
190
186
///
191
187
/// function bar(foo) {
192
- /// switch(foo) {
193
- /// case 1:
194
- /// doSomething();
195
- /// return;
196
- ///
197
- /// case 2:
198
- /// doSomething();
199
- /// }
188
+ /// switch(foo) {
189
+ /// case 1:
190
+ /// doSomething();
191
+ /// return;
192
+ ///
193
+ /// case 2:
194
+ /// doSomething();
195
+ /// }
200
196
/// }
201
197
///
202
198
/// switch(foo) {
203
- /// case 1:
204
- /// doSomething();
205
- /// throw new Error("Boo!");
199
+ /// case 1:
200
+ /// doSomething();
201
+ /// throw new Error("Boo!");
206
202
///
207
- /// case 2:
208
- /// doSomething();
203
+ /// case 2:
204
+ /// doSomething();
209
205
/// }
210
206
///
211
207
/// switch(foo) {
212
- /// case 1:
213
- /// case 2:
214
- /// doSomething();
208
+ /// case 1:
209
+ /// case 2:
210
+ /// doSomething();
215
211
/// }
216
212
///
217
213
/// switch(foo) {
218
- /// case 1: case 2:
219
- /// doSomething();
214
+ /// case 1: case 2:
215
+ /// doSomething();
220
216
/// }
221
217
///
222
218
/// switch(foo) {
223
- /// case 1:
224
- /// doSomething();
225
- /// // falls through
219
+ /// case 1:
220
+ /// doSomething();
221
+ /// // falls through
226
222
///
227
- /// case 2:
228
- /// doSomething();
223
+ /// case 2:
224
+ /// doSomething();
229
225
/// }
230
226
///
231
227
/// switch(foo) {
232
- /// case 1: {
233
- /// doSomething();
234
- /// // falls through
235
- /// }
236
- ///
237
- /// case 2: {
238
- /// doSomethingElse();
239
- /// }
228
+ /// case 1: {
229
+ /// doSomething();
230
+ /// // falls through
231
+ /// }
232
+ ///
233
+ /// case 2: {
234
+ /// doSomethingElse();
235
+ /// }
240
236
/// }
241
237
/// ```
242
238
///
@@ -278,42 +274,29 @@ impl Rule for NoFallthrough {
278
274
let fallthroughs: FxHashSet < BlockNodeId > = neighbors_filtered_by_edge_weight (
279
275
graph,
280
276
switch_id,
281
- & |e | match e {
277
+ & |edge_type | match edge_type {
282
278
EdgeType :: Normal | EdgeType :: Jump | EdgeType :: Error ( ErrorEdgeKind :: Explicit ) => {
283
279
None
284
280
}
285
281
_ => Some ( None ) ,
286
282
} ,
287
- & mut |node, last_cond : Option < BlockNodeId > | {
288
- let node = * node;
289
-
283
+ & mut |& node, last_cond : Option < BlockNodeId > | {
290
284
if node == switch_id {
291
- return ( last_cond, true ) ;
292
- }
293
- if node == default_or_exit {
294
- return ( last_cond, false ) ;
295
- }
296
- if tests. contains_key ( & node) {
297
- return ( last_cond, true ) ;
298
- }
299
- if cfg. basic_block ( node) . is_unreachable ( ) {
300
- return ( None , false ) ;
301
- }
302
-
303
- let fallthrough = graph
304
- . edges_directed ( node, Direction :: Outgoing )
305
- . find ( |it| {
306
- let target = it. target ( ) ;
307
- if let Some ( default) = default {
308
- if default == target {
309
- return true ;
310
- }
311
- }
312
- tests. contains_key ( & target)
313
- } )
314
- . map ( |e| e. target ( ) ) ;
285
+ ( last_cond, true )
286
+ } else if node == default_or_exit {
287
+ ( last_cond, false )
288
+ } else if tests. contains_key ( & node) {
289
+ ( last_cond, true )
290
+ } else if cfg. basic_block ( node) . is_unreachable ( ) {
291
+ ( None , false )
292
+ } else {
293
+ let fallthrough = graph
294
+ . edges_directed ( node, Direction :: Outgoing )
295
+ . map ( |edge| edge. target ( ) )
296
+ . find ( |target| Some ( * target) == default || tests. contains_key ( target) ) ;
315
297
316
- ( fallthrough, fallthrough. is_none ( ) )
298
+ ( fallthrough, fallthrough. is_none ( ) )
299
+ }
317
300
} ,
318
301
)
319
302
. into_iter ( )
0 commit comments