Skip to content

Commit 1cf765d

Browse files
author
Andy Hanson
committed
Lint for fallthrough in switch
1 parent 5e4b8d6 commit 1cf765d

20 files changed

+64
-38
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,7 @@ namespace ts {
14131413
if (isObjectLiteralOrClassExpressionMethod(node)) {
14141414
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike | ContainerFlags.IsObjectLiteralOrClassExpressionMethod;
14151415
}
1416+
// falls through
14161417
case SyntaxKind.Constructor:
14171418
case SyntaxKind.FunctionDeclaration:
14181419
case SyntaxKind.MethodSignature:
@@ -1714,7 +1715,7 @@ namespace ts {
17141715
declareModuleMember(node, symbolFlags, symbolExcludes);
17151716
break;
17161717
}
1717-
// fall through.
1718+
// falls through
17181719
default:
17191720
if (!blockScopeContainer.locals) {
17201721
blockScopeContainer.locals = createMap<Symbol>();
@@ -2006,6 +2007,7 @@ namespace ts {
20062007
bindBlockScopedDeclaration(<Declaration>parentNode, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
20072008
break;
20082009
}
2010+
// falls through
20092011
case SyntaxKind.ThisKeyword:
20102012
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
20112013
node.flowNode = currentFlow;
@@ -2183,7 +2185,7 @@ namespace ts {
21832185
if (!isFunctionLike(node.parent)) {
21842186
return;
21852187
}
2186-
// Fall through
2188+
// falls through
21872189
case SyntaxKind.ModuleBlock:
21882190
return updateStrictModeStatementList((<Block | ModuleBlock>node).statements);
21892191
}

src/compiler/checker.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ namespace ts {
872872
case SyntaxKind.SourceFile:
873873
if (!isExternalOrCommonJsModule(<SourceFile>location)) break;
874874
isInExternalModule = true;
875+
// falls through
875876
case SyntaxKind.ModuleDeclaration:
876877
const moduleExports = getSymbolOfNode(location).exports;
877878
if (location.kind === SyntaxKind.SourceFile || isAmbientModule(location)) {
@@ -1872,6 +1873,7 @@ namespace ts {
18721873
if (!isExternalOrCommonJsModule(<SourceFile>location)) {
18731874
break;
18741875
}
1876+
// falls through
18751877
case SyntaxKind.ModuleDeclaration:
18761878
if (result = callback(getSymbolOfNode(location).exports)) {
18771879
return result;
@@ -3592,7 +3594,7 @@ namespace ts {
35923594
// If the binding pattern is empty, this variable declaration is not visible
35933595
return false;
35943596
}
3595-
// Otherwise fall through
3597+
// falls through
35963598
case SyntaxKind.ModuleDeclaration:
35973599
case SyntaxKind.ClassDeclaration:
35983600
case SyntaxKind.InterfaceDeclaration:
@@ -3623,7 +3625,8 @@ namespace ts {
36233625
// Private/protected properties/methods are not visible
36243626
return false;
36253627
}
3626-
// Public properties/methods are visible if its parents are visible, so const it fall into next case statement
3628+
// Public properties/methods are visible if its parents are visible, so
3629+
// falls through
36273630

36283631
case SyntaxKind.Constructor:
36293632
case SyntaxKind.ConstructSignature:
@@ -20863,7 +20866,7 @@ namespace ts {
2086320866
}
2086420867
break;
2086520868
}
20866-
// fallthrough
20869+
// falls through
2086720870
case SyntaxKind.ClassDeclaration:
2086820871
case SyntaxKind.EnumDeclaration:
2086920872
case SyntaxKind.FunctionDeclaration:
@@ -21498,6 +21501,7 @@ namespace ts {
2149821501
if (!isExternalOrCommonJsModule(<SourceFile>location)) {
2149921502
break;
2150021503
}
21504+
// falls through
2150121505
case SyntaxKind.ModuleDeclaration:
2150221506
copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember);
2150321507
break;
@@ -21509,7 +21513,8 @@ namespace ts {
2150921513
if (className) {
2151021514
copySymbol(location.symbol, meaning);
2151121515
}
21512-
// fall through; this fall-through is necessary because we would like to handle
21516+
// falls through
21517+
// this fall-through is necessary because we would like to handle
2151321518
// type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration
2151421519
case SyntaxKind.ClassDeclaration:
2151521520
case SyntaxKind.InterfaceDeclaration:
@@ -21795,7 +21800,7 @@ namespace ts {
2179521800
return sig.thisParameter;
2179621801
}
2179721802
}
21798-
// fallthrough
21803+
// falls through
2179921804

2180021805
case SyntaxKind.SuperKeyword:
2180121806
const type = isPartOfExpression(node) ? getTypeOfExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node);
@@ -21823,7 +21828,7 @@ namespace ts {
2182321828
if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) {
2182421829
return resolveExternalModuleName(node, <LiteralExpression>node);
2182521830
}
21826-
// Fall through
21831+
// falls through
2182721832

2182821833
case SyntaxKind.NumericLiteral:
2182921834
// index access

src/compiler/parser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,6 +3576,7 @@ namespace ts {
35763576
if (isAwaitExpression()) {
35773577
return parseAwaitExpression();
35783578
}
3579+
// falls through
35793580
default:
35803581
return parseIncrementExpression();
35813582
}
@@ -3609,8 +3610,8 @@ namespace ts {
36093610
if (sourceFile.languageVariant !== LanguageVariant.JSX) {
36103611
return false;
36113612
}
3612-
// We are in JSX context and the token is part of JSXElement.
3613-
// Fall through
3613+
// We are in JSX context and the token is part of JSXElement.
3614+
// falls through
36143615
default:
36153616
return true;
36163617
}
@@ -6557,7 +6558,8 @@ namespace ts {
65576558
indent += scanner.getTokenText().length;
65586559
break;
65596560
}
6560-
// FALLTHROUGH otherwise to record the * as a comment
6561+
// record the * as a comment
6562+
// falls through
65616563
default:
65626564
state = JSDocState.SavingComments; // leading identifiers start recording as well
65636565
pushComment(scanner.getTokenText());
@@ -6783,6 +6785,7 @@ namespace ts {
67836785
break;
67846786
case SyntaxKind.Identifier:
67856787
canParseTag = false;
6788+
break;
67866789
case SyntaxKind.EndOfFileToken:
67876790
break;
67886791
}

src/compiler/program.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,7 @@ namespace ts {
941941
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
942942
return;
943943
}
944-
945-
// Pass through
944+
// falls through
946945
case SyntaxKind.MethodDeclaration:
947946
case SyntaxKind.MethodSignature:
948947
case SyntaxKind.Constructor:
@@ -1022,7 +1021,7 @@ namespace ts {
10221021
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file));
10231022
return;
10241023
}
1025-
// pass through
1024+
// falls through
10261025
case SyntaxKind.VariableStatement:
10271026
// Check modifiers
10281027
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration | VariableStatement>parent).modifiers) {
@@ -1070,7 +1069,8 @@ namespace ts {
10701069
if (isConstValid) {
10711070
continue;
10721071
}
1073-
// Fallthrough to report error
1072+
// to report error,
1073+
// falls through
10741074
case SyntaxKind.PublicKeyword:
10751075
case SyntaxKind.PrivateKeyword:
10761076
case SyntaxKind.ProtectedKeyword:

src/compiler/scanner.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ namespace ts {
306306
if (text.charCodeAt(pos) === CharacterCodes.lineFeed) {
307307
pos++;
308308
}
309+
// falls through
309310
case CharacterCodes.lineFeed:
310311
result.push(lineStart);
311312
lineStart = pos;
@@ -452,6 +453,7 @@ namespace ts {
452453
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
453454
pos++;
454455
}
456+
// falls through
455457
case CharacterCodes.lineFeed:
456458
pos++;
457459
if (stopAfterLineBreak) {
@@ -623,6 +625,7 @@ namespace ts {
623625
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
624626
pos++;
625627
}
628+
// falls through
626629
case CharacterCodes.lineFeed:
627630
pos++;
628631
if (trailing) {
@@ -1067,7 +1070,7 @@ namespace ts {
10671070
if (pos < end && text.charCodeAt(pos) === CharacterCodes.lineFeed) {
10681071
pos++;
10691072
}
1070-
// fall through
1073+
// falls through
10711074
case CharacterCodes.lineFeed:
10721075
case CharacterCodes.lineSeparator:
10731076
case CharacterCodes.paragraphSeparator:
@@ -1449,6 +1452,7 @@ namespace ts {
14491452
// This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero
14501453
// can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being
14511454
// permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do).
1455+
// falls through
14521456
case CharacterCodes._1:
14531457
case CharacterCodes._2:
14541458
case CharacterCodes._3:

src/compiler/transformers/module/system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ namespace ts {
477477
// module is imported only for side-effects, no emit required
478478
break;
479479
}
480+
// falls through
480481

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

src/compiler/utilities.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ namespace ts {
733733
// At this point, node is either a qualified name or an identifier
734734
Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression,
735735
"'node' was expected to be a qualified name, identifier or property access in 'isPartOfTypeNode'.");
736+
// falls through
736737
case SyntaxKind.QualifiedName:
737738
case SyntaxKind.PropertyAccessExpression:
738739
case SyntaxKind.ThisKeyword:
@@ -842,6 +843,7 @@ namespace ts {
842843
if (operand) {
843844
traverse(operand);
844845
}
846+
return;
845847
case SyntaxKind.EnumDeclaration:
846848
case SyntaxKind.InterfaceDeclaration:
847849
case SyntaxKind.ModuleDeclaration:
@@ -1059,7 +1061,7 @@ namespace ts {
10591061
if (!includeArrowFunctions) {
10601062
continue;
10611063
}
1062-
// Fall through
1064+
// falls through
10631065
case SyntaxKind.FunctionDeclaration:
10641066
case SyntaxKind.FunctionExpression:
10651067
case SyntaxKind.ModuleDeclaration:
@@ -1118,6 +1120,7 @@ namespace ts {
11181120
if (!stopOnFunctions) {
11191121
continue;
11201122
}
1123+
// falls through
11211124
case SyntaxKind.PropertyDeclaration:
11221125
case SyntaxKind.PropertySignature:
11231126
case SyntaxKind.MethodDeclaration:
@@ -1317,7 +1320,7 @@ namespace ts {
13171320
if (node.parent.kind === SyntaxKind.TypeQuery || isJSXTagName(node)) {
13181321
return true;
13191322
}
1320-
// fall through
1323+
// falls through
13211324
case SyntaxKind.NumericLiteral:
13221325
case SyntaxKind.StringLiteral:
13231326
case SyntaxKind.ThisKeyword:
@@ -1995,7 +1998,7 @@ namespace ts {
19951998
if (node.asteriskToken) {
19961999
flags |= FunctionFlags.Generator;
19972000
}
1998-
// fall through
2001+
// falls through
19992002
case SyntaxKind.ArrowFunction:
20002003
if (hasModifier(node, ModifierFlags.Async)) {
20012004
flags |= FunctionFlags.Async;

src/compiler/visitor.ts

Lines changed: 4 additions & 2 deletions
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:

src/services/breakpoints.ts

Lines changed: 5 additions & 2 deletions
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));

src/services/classifier.ts

Lines changed: 1 addition & 1 deletion
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;

0 commit comments

Comments
 (0)