Skip to content

Commit 60fe5a8

Browse files
author
Andy
authored
Merge pull request #14886 from Microsoft/fallthrough
Lint for fallthrough in switch
2 parents 0a77bd2 + 455492d commit 60fe5a8

20 files changed

+63
-37
lines changed

Diff for: src/compiler/binder.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,7 @@ namespace ts {
14141414
if (isObjectLiteralOrClassExpressionMethod(node)) {
14151415
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike | ContainerFlags.IsObjectLiteralOrClassExpressionMethod;
14161416
}
1417+
// falls through
14171418
case SyntaxKind.Constructor:
14181419
case SyntaxKind.FunctionDeclaration:
14191420
case SyntaxKind.MethodSignature:
@@ -1715,7 +1716,7 @@ namespace ts {
17151716
declareModuleMember(node, symbolFlags, symbolExcludes);
17161717
break;
17171718
}
1718-
// fall through.
1719+
// falls through
17191720
default:
17201721
if (!blockScopeContainer.locals) {
17211722
blockScopeContainer.locals = createMap<Symbol>();
@@ -2009,6 +2010,7 @@ namespace ts {
20092010
bindBlockScopedDeclaration(<Declaration>parentNode, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
20102011
break;
20112012
}
2013+
// falls through
20122014
case SyntaxKind.ThisKeyword:
20132015
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
20142016
node.flowNode = currentFlow;
@@ -2184,7 +2186,7 @@ namespace ts {
21842186
if (!isFunctionLike(node.parent)) {
21852187
return;
21862188
}
2187-
// Fall through
2189+
// falls through
21882190
case SyntaxKind.ModuleBlock:
21892191
return updateStrictModeStatementList((<Block | ModuleBlock>node).statements);
21902192
}

Diff for: src/compiler/checker.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ namespace ts {
902902
case SyntaxKind.SourceFile:
903903
if (!isExternalOrCommonJsModule(<SourceFile>location)) break;
904904
isInExternalModule = true;
905+
// falls through
905906
case SyntaxKind.ModuleDeclaration:
906907
const moduleExports = getSymbolOfNode(location).exports;
907908
if (location.kind === SyntaxKind.SourceFile || isAmbientModule(location)) {
@@ -1938,6 +1939,7 @@ namespace ts {
19381939
if (!isExternalOrCommonJsModule(<SourceFile>location)) {
19391940
break;
19401941
}
1942+
// falls through
19411943
case SyntaxKind.ModuleDeclaration:
19421944
if (result = callback(getSymbolOfNode(location).exports)) {
19431945
return result;
@@ -3658,7 +3660,7 @@ namespace ts {
36583660
// If the binding pattern is empty, this variable declaration is not visible
36593661
return false;
36603662
}
3661-
// Otherwise fall through
3663+
// falls through
36623664
case SyntaxKind.ModuleDeclaration:
36633665
case SyntaxKind.ClassDeclaration:
36643666
case SyntaxKind.InterfaceDeclaration:
@@ -3689,7 +3691,8 @@ namespace ts {
36893691
// Private/protected properties/methods are not visible
36903692
return false;
36913693
}
3692-
// Public properties/methods are visible if its parents are visible, so const it fall into next case statement
3694+
// Public properties/methods are visible if its parents are visible, so:
3695+
// falls through
36933696

36943697
case SyntaxKind.Constructor:
36953698
case SyntaxKind.ConstructSignature:
@@ -21050,7 +21053,7 @@ namespace ts {
2105021053
}
2105121054
break;
2105221055
}
21053-
// fallthrough
21056+
// falls through
2105421057
case SyntaxKind.ClassDeclaration:
2105521058
case SyntaxKind.EnumDeclaration:
2105621059
case SyntaxKind.FunctionDeclaration:
@@ -21685,6 +21688,7 @@ namespace ts {
2168521688
if (!isExternalOrCommonJsModule(<SourceFile>location)) {
2168621689
break;
2168721690
}
21691+
// falls through
2168821692
case SyntaxKind.ModuleDeclaration:
2168921693
copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember);
2169021694
break;
@@ -21696,7 +21700,8 @@ namespace ts {
2169621700
if (className) {
2169721701
copySymbol(location.symbol, meaning);
2169821702
}
21699-
// fall through; this fall-through is necessary because we would like to handle
21703+
// falls through
21704+
// this fall-through is necessary because we would like to handle
2170021705
// type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration
2170121706
case SyntaxKind.ClassDeclaration:
2170221707
case SyntaxKind.InterfaceDeclaration:
@@ -21985,7 +21990,7 @@ namespace ts {
2198521990
return sig.thisParameter;
2198621991
}
2198721992
}
21988-
// fallthrough
21993+
// falls through
2198921994

2199021995
case SyntaxKind.SuperKeyword:
2199121996
const type = isPartOfExpression(node) ? getTypeOfExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node);
@@ -22013,7 +22018,7 @@ namespace ts {
2201322018
if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) {
2201422019
return resolveExternalModuleName(node, <LiteralExpression>node);
2201522020
}
22016-
// Fall through
22021+
// falls through
2201722022

2201822023
case SyntaxKind.NumericLiteral:
2201922024
// index access

Diff for: src/compiler/parser.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -3573,6 +3573,7 @@ namespace ts {
35733573
if (isAwaitExpression()) {
35743574
return parseAwaitExpression();
35753575
}
3576+
// falls through
35763577
default:
35773578
return parseIncrementExpression();
35783579
}
@@ -3606,8 +3607,8 @@ namespace ts {
36063607
if (sourceFile.languageVariant !== LanguageVariant.JSX) {
36073608
return false;
36083609
}
3609-
// We are in JSX context and the token is part of JSXElement.
3610-
// Fall through
3610+
// We are in JSX context and the token is part of JSXElement.
3611+
// falls through
36113612
default:
36123613
return true;
36133614
}
@@ -6571,7 +6572,8 @@ namespace ts {
65716572
indent += scanner.getTokenText().length;
65726573
break;
65736574
}
6574-
// FALLTHROUGH otherwise to record the * as a comment
6575+
// record the * as a comment
6576+
// falls through
65756577
default:
65766578
state = JSDocState.SavingComments; // leading identifiers start recording as well
65776579
pushComment(scanner.getTokenText());
@@ -6797,6 +6799,7 @@ namespace ts {
67976799
break;
67986800
case SyntaxKind.Identifier:
67996801
canParseTag = false;
6802+
break;
68006803
case SyntaxKind.EndOfFileToken:
68016804
break;
68026805
}

Diff for: src/compiler/program.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,7 @@ namespace ts {
967967
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
968968
return;
969969
}
970-
971-
// Pass through
970+
// falls through
972971
case SyntaxKind.MethodDeclaration:
973972
case SyntaxKind.MethodSignature:
974973
case SyntaxKind.Constructor:
@@ -1048,7 +1047,7 @@ namespace ts {
10481047
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file));
10491048
return;
10501049
}
1051-
// pass through
1050+
// falls through
10521051
case SyntaxKind.VariableStatement:
10531052
// Check modifiers
10541053
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration | VariableStatement>parent).modifiers) {
@@ -1096,7 +1095,8 @@ namespace ts {
10961095
if (isConstValid) {
10971096
continue;
10981097
}
1099-
// Fallthrough to report error
1098+
// to report error,
1099+
// falls through
11001100
case SyntaxKind.PublicKeyword:
11011101
case SyntaxKind.PrivateKeyword:
11021102
case SyntaxKind.ProtectedKeyword:

Diff for: src/compiler/scanner.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ namespace ts {
308308
if (text.charCodeAt(pos) === CharacterCodes.lineFeed) {
309309
pos++;
310310
}
311+
// falls through
311312
case CharacterCodes.lineFeed:
312313
result.push(lineStart);
313314
lineStart = pos;
@@ -454,6 +455,7 @@ namespace ts {
454455
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
455456
pos++;
456457
}
458+
// falls through
457459
case CharacterCodes.lineFeed:
458460
pos++;
459461
if (stopAfterLineBreak) {
@@ -625,6 +627,7 @@ namespace ts {
625627
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
626628
pos++;
627629
}
630+
// falls through
628631
case CharacterCodes.lineFeed:
629632
pos++;
630633
if (trailing) {
@@ -1072,7 +1075,7 @@ namespace ts {
10721075
if (pos < end && text.charCodeAt(pos) === CharacterCodes.lineFeed) {
10731076
pos++;
10741077
}
1075-
// fall through
1078+
// falls through
10761079
case CharacterCodes.lineFeed:
10771080
case CharacterCodes.lineSeparator:
10781081
case CharacterCodes.paragraphSeparator:
@@ -1459,6 +1462,7 @@ namespace ts {
14591462
// This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero
14601463
// can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being
14611464
// permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do).
1465+
// falls through
14621466
case CharacterCodes._1:
14631467
case CharacterCodes._2:
14641468
case CharacterCodes._3:

Diff for: src/compiler/transformers/module/system.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ namespace ts {
479479
// module is imported only for side-effects, no emit required
480480
break;
481481
}
482+
// falls through
482483

483-
// fall-through
484484
case SyntaxKind.ImportEqualsDeclaration:
485485
Debug.assert(importVariableName !== undefined);
486486
// save import into the local

Diff for: src/compiler/utilities.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ namespace ts {
674674
// At this point, node is either a qualified name or an identifier
675675
Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression,
676676
"'node' was expected to be a qualified name, identifier or property access in 'isPartOfTypeNode'.");
677+
// falls through
677678
case SyntaxKind.QualifiedName:
678679
case SyntaxKind.PropertyAccessExpression:
679680
case SyntaxKind.ThisKeyword:
@@ -783,6 +784,7 @@ namespace ts {
783784
if (operand) {
784785
traverse(operand);
785786
}
787+
return;
786788
case SyntaxKind.EnumDeclaration:
787789
case SyntaxKind.InterfaceDeclaration:
788790
case SyntaxKind.ModuleDeclaration:
@@ -1000,7 +1002,7 @@ namespace ts {
10001002
if (!includeArrowFunctions) {
10011003
continue;
10021004
}
1003-
// Fall through
1005+
// falls through
10041006
case SyntaxKind.FunctionDeclaration:
10051007
case SyntaxKind.FunctionExpression:
10061008
case SyntaxKind.ModuleDeclaration:
@@ -1059,6 +1061,7 @@ namespace ts {
10591061
if (!stopOnFunctions) {
10601062
continue;
10611063
}
1064+
// falls through
10621065
case SyntaxKind.PropertyDeclaration:
10631066
case SyntaxKind.PropertySignature:
10641067
case SyntaxKind.MethodDeclaration:
@@ -1258,7 +1261,7 @@ namespace ts {
12581261
if (node.parent.kind === SyntaxKind.TypeQuery || isJSXTagName(node)) {
12591262
return true;
12601263
}
1261-
// fall through
1264+
// falls through
12621265
case SyntaxKind.NumericLiteral:
12631266
case SyntaxKind.StringLiteral:
12641267
case SyntaxKind.ThisKeyword:
@@ -1940,7 +1943,7 @@ namespace ts {
19401943
if (node.asteriskToken) {
19411944
flags |= FunctionFlags.Generator;
19421945
}
1943-
// fall through
1946+
// falls through
19441947
case SyntaxKind.ArrowFunction:
19451948
if (hasModifier(node, ModifierFlags.Async)) {
19461949
flags |= FunctionFlags.Async;

Diff for: src/compiler/visitor.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ namespace ts {
322322
nodesVisitor((<UnionOrIntersectionTypeNode>node).types, visitor, isTypeNode));
323323

324324
case SyntaxKind.ParenthesizedType:
325-
Debug.fail("not implemented.");
325+
throw Debug.fail("not implemented.");
326326

327327
case SyntaxKind.TypeOperator:
328328
return updateTypeOperatorNode(<TypeOperatorNode>node, visitNode((<TypeOperatorNode>node).type, visitor, isTypeNode));
@@ -1289,6 +1289,7 @@ namespace ts {
12891289

12901290
case SyntaxKind.JsxAttributes:
12911291
result = reduceNodes((<JsxAttributes>node).properties, cbNodes, result);
1292+
break;
12921293

12931294
case SyntaxKind.JsxClosingElement:
12941295
result = reduceNode((<JsxClosingElement>node).tagName, cbNode, result);
@@ -1310,7 +1311,7 @@ namespace ts {
13101311
// Clauses
13111312
case SyntaxKind.CaseClause:
13121313
result = reduceNode((<CaseClause>node).expression, cbNode, result);
1313-
// fall-through
1314+
// falls through
13141315

13151316
case SyntaxKind.DefaultClause:
13161317
result = reduceNodes((<CaseClause | DefaultClause>node).statements, cbNodes, result);
@@ -1344,6 +1345,7 @@ namespace ts {
13441345
case SyntaxKind.EnumMember:
13451346
result = reduceNode((<EnumMember>node).name, cbNode, result);
13461347
result = reduceNode((<EnumMember>node).initializer, cbNode, result);
1348+
break;
13471349

13481350
// Top-level nodes
13491351
case SyntaxKind.SourceFile:

Diff for: src/services/breakpoints.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace ts.BreakpointResolver {
9797
if (isFunctionBlock(node)) {
9898
return spanInFunctionBlock(<Block>node);
9999
}
100-
// Fall through
100+
// falls through
101101
case SyntaxKind.ModuleBlock:
102102
return spanInBlock(<Block>node);
103103

@@ -186,6 +186,7 @@ namespace ts.BreakpointResolver {
186186
if (getModuleInstanceState(node) !== ModuleInstanceState.Instantiated) {
187187
return undefined;
188188
}
189+
// falls through
189190

190191
case SyntaxKind.ClassDeclaration:
191192
case SyntaxKind.EnumDeclaration:
@@ -473,6 +474,7 @@ namespace ts.BreakpointResolver {
473474
if (getModuleInstanceState(block.parent) !== ModuleInstanceState.Instantiated) {
474475
return undefined;
475476
}
477+
// falls through
476478

477479
// Set on parent if on same line otherwise on first statement
478480
case SyntaxKind.WhileStatement:
@@ -582,6 +584,7 @@ namespace ts.BreakpointResolver {
582584
if (getModuleInstanceState(node.parent.parent) !== ModuleInstanceState.Instantiated) {
583585
return undefined;
584586
}
587+
// falls through
585588

586589
case SyntaxKind.EnumDeclaration:
587590
case SyntaxKind.ClassDeclaration:
@@ -593,7 +596,7 @@ namespace ts.BreakpointResolver {
593596
// Span on close brace token
594597
return textSpan(node);
595598
}
596-
// fall through
599+
// falls through
597600

598601
case SyntaxKind.CatchClause:
599602
return spanInNode(lastOrUndefined((<Block>node.parent).statements));

Diff for: src/services/classifier.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ namespace ts {
160160
case EndOfLineState.InTemplateMiddleOrTail:
161161
text = "}\n" + text;
162162
offset = 2;
163-
// fallthrough
163+
// falls through
164164
case EndOfLineState.InTemplateSubstitutionPosition:
165165
templateStack.push(SyntaxKind.TemplateHead);
166166
break;

Diff for: src/services/codefixes/importFixes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ namespace ts.codefix {
4242

4343
switch (this.compareModuleSpecifiers(existingAction.moduleSpecifier, newAction.moduleSpecifier)) {
4444
case ModuleSpecifierComparison.Better:
45-
// the new one is not worth considering if it is a new improt.
45+
// the new one is not worth considering if it is a new import.
4646
// However if it is instead a insertion into existing import, the user might want to use
4747
// the module specifier even it is worse by our standards. So keep it.
4848
if (newAction.kind === "NewImport") {
4949
return;
5050
}
51+
// falls through
5152
case ModuleSpecifierComparison.Equal:
5253
// the current one is safe. But it is still possible that the new one is worse
5354
// than another existing one. For example, you may have new imports from "./foo/bar"

Diff for: src/services/codefixes/unusedIdentifierFixes.ts

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace ts.codefix {
5858
return deleteNodeInList(token.parent);
5959
}
6060
}
61+
// TODO: #14885
62+
// falls through
6163

6264
case SyntaxKind.TypeParameter:
6365
const typeParameters = (<DeclarationWithTypeParameters>token.parent.parent).typeParameters;

0 commit comments

Comments
 (0)