@@ -17,6 +17,7 @@ import {
17
17
isContinueStatement ,
18
18
isExpressionStatement ,
19
19
isIfStatement ,
20
+ isLabeledStatement ,
20
21
isReturnStatement ,
21
22
isSwitchStatement ,
22
23
isThrowStatement ,
@@ -195,18 +196,6 @@ function getIfBranchViolations(
195
196
return violations . flatMap ( incompleteBranchViolation ) ;
196
197
}
197
198
198
- /**
199
- * Is the given statement, when inside a switch statement, a returning branch?
200
- */
201
- function isSwitchReturningBranch ( statement : TSESTree . Statement ) {
202
- return (
203
- // Another instance of this rule will check nested switch statements.
204
- isSwitchStatement ( statement ) ||
205
- isReturnStatement ( statement ) ||
206
- isThrowStatement ( statement )
207
- ) ;
208
- }
209
-
210
199
/**
211
200
* Get all of the violations in the given switch statement assuming switch
212
201
* statements are allowed.
@@ -217,6 +206,8 @@ function getSwitchViolations(
217
206
) : RuleResult < keyof typeof errorMessages , Options > [ "descriptors" ] {
218
207
const isNeverExpressions = getIsNeverExpressions ( context ) ;
219
208
209
+ const label = isLabeledStatement ( node . parent ) ? node . parent . label . name : null ;
210
+
220
211
const violations = node . cases . filter ( ( branch ) => {
221
212
if ( branch . consequent . length === 0 ) {
222
213
return false ;
@@ -241,6 +232,22 @@ function getSwitchViolations(
241
232
} ) ;
242
233
243
234
return violations . flatMap ( incompleteBranchViolation ) ;
235
+
236
+ /**
237
+ * Is the given statement, when inside a switch statement, a returning branch?
238
+ */
239
+ function isSwitchReturningBranch ( statement : TSESTree . Statement ) {
240
+ return (
241
+ // Another instance of this rule will check nested switch statements.
242
+ isSwitchStatement ( statement ) ||
243
+ isReturnStatement ( statement ) ||
244
+ isThrowStatement ( statement ) ||
245
+ ( isBreakStatement ( statement ) &&
246
+ statement . label !== null &&
247
+ statement . label . name !== label ) ||
248
+ isContinueStatement ( statement )
249
+ ) ;
250
+ }
244
251
}
245
252
246
253
/**
0 commit comments