Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint for fallthrough in switch #14886

Merged
4 commits merged into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,7 @@ namespace ts {
if (isObjectLiteralOrClassExpressionMethod(node)) {
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike | ContainerFlags.IsObjectLiteralOrClassExpressionMethod;
}
// falls through
case SyntaxKind.Constructor:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.MethodSignature:
Expand Down Expand Up @@ -1715,7 +1716,7 @@ namespace ts {
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
}
// fall through.
// falls through
default:
if (!blockScopeContainer.locals) {
blockScopeContainer.locals = createMap<Symbol>();
Expand Down Expand Up @@ -2009,6 +2010,7 @@ namespace ts {
bindBlockScopedDeclaration(<Declaration>parentNode, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
break;
}
// falls through
case SyntaxKind.ThisKeyword:
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
node.flowNode = currentFlow;
Expand Down Expand Up @@ -2184,7 +2186,7 @@ namespace ts {
if (!isFunctionLike(node.parent)) {
return;
}
// Fall through
// falls through
case SyntaxKind.ModuleBlock:
return updateStrictModeStatementList((<Block | ModuleBlock>node).statements);
}
Expand Down
17 changes: 11 additions & 6 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ namespace ts {
case SyntaxKind.SourceFile:
if (!isExternalOrCommonJsModule(<SourceFile>location)) break;
isInExternalModule = true;
// falls through
case SyntaxKind.ModuleDeclaration:
const moduleExports = getSymbolOfNode(location).exports;
if (location.kind === SyntaxKind.SourceFile || isAmbientModule(location)) {
Expand Down Expand Up @@ -1938,6 +1939,7 @@ namespace ts {
if (!isExternalOrCommonJsModule(<SourceFile>location)) {
break;
}
// falls through
case SyntaxKind.ModuleDeclaration:
if (result = callback(getSymbolOfNode(location).exports)) {
return result;
Expand Down Expand Up @@ -3658,7 +3660,7 @@ namespace ts {
// If the binding pattern is empty, this variable declaration is not visible
return false;
}
// Otherwise fall through
// falls through
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
Expand Down Expand Up @@ -3689,7 +3691,8 @@ namespace ts {
// Private/protected properties/methods are not visible
return false;
}
// Public properties/methods are visible if its parents are visible, so const it fall into next case statement
// Public properties/methods are visible if its parents are visible, so:
// falls through

case SyntaxKind.Constructor:
case SyntaxKind.ConstructSignature:
Expand Down Expand Up @@ -21050,7 +21053,7 @@ namespace ts {
}
break;
}
// fallthrough
// falls through
case SyntaxKind.ClassDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.FunctionDeclaration:
Expand Down Expand Up @@ -21685,6 +21688,7 @@ namespace ts {
if (!isExternalOrCommonJsModule(<SourceFile>location)) {
break;
}
// falls through
case SyntaxKind.ModuleDeclaration:
copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember);
break;
Expand All @@ -21696,7 +21700,8 @@ namespace ts {
if (className) {
copySymbol(location.symbol, meaning);
}
// fall through; this fall-through is necessary because we would like to handle
// falls through
// this fall-through is necessary because we would like to handle
// type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
Expand Down Expand Up @@ -21985,7 +21990,7 @@ namespace ts {
return sig.thisParameter;
}
}
// fallthrough
// falls through

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

case SyntaxKind.NumericLiteral:
// index access
Expand Down
9 changes: 6 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,7 @@ namespace ts {
if (isAwaitExpression()) {
return parseAwaitExpression();
}
// falls through
default:
return parseIncrementExpression();
}
Expand Down Expand Up @@ -3606,8 +3607,8 @@ namespace ts {
if (sourceFile.languageVariant !== LanguageVariant.JSX) {
return false;
}
// We are in JSX context and the token is part of JSXElement.
// Fall through
// We are in JSX context and the token is part of JSXElement.
// falls through
default:
return true;
}
Expand Down Expand Up @@ -6571,7 +6572,8 @@ namespace ts {
indent += scanner.getTokenText().length;
break;
}
// FALLTHROUGH otherwise to record the * as a comment
// record the * as a comment
// falls through
default:
state = JSDocState.SavingComments; // leading identifiers start recording as well
pushComment(scanner.getTokenText());
Expand Down Expand Up @@ -6797,6 +6799,7 @@ namespace ts {
break;
case SyntaxKind.Identifier:
canParseTag = false;
break;
case SyntaxKind.EndOfFileToken:
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,7 @@ namespace ts {
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
return;
}

// Pass through
// falls through
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.Constructor:
Expand Down Expand Up @@ -1048,7 +1047,7 @@ namespace ts {
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file));
return;
}
// pass through
// falls through
case SyntaxKind.VariableStatement:
// Check modifiers
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration | VariableStatement>parent).modifiers) {
Expand Down Expand Up @@ -1096,7 +1095,8 @@ namespace ts {
if (isConstValid) {
continue;
}
// Fallthrough to report error
// to report error,
// falls through
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ namespace ts {
if (text.charCodeAt(pos) === CharacterCodes.lineFeed) {
pos++;
}
// falls through
case CharacterCodes.lineFeed:
result.push(lineStart);
lineStart = pos;
Expand Down Expand Up @@ -454,6 +455,7 @@ namespace ts {
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
pos++;
}
// falls through
case CharacterCodes.lineFeed:
pos++;
if (stopAfterLineBreak) {
Expand Down Expand Up @@ -625,6 +627,7 @@ namespace ts {
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
pos++;
}
// falls through
case CharacterCodes.lineFeed:
pos++;
if (trailing) {
Expand Down Expand Up @@ -1072,7 +1075,7 @@ namespace ts {
if (pos < end && text.charCodeAt(pos) === CharacterCodes.lineFeed) {
pos++;
}
// fall through
// falls through
case CharacterCodes.lineFeed:
case CharacterCodes.lineSeparator:
case CharacterCodes.paragraphSeparator:
Expand Down Expand Up @@ -1459,6 +1462,7 @@ namespace ts {
// This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero
// can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being
// permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do).
// falls through
case CharacterCodes._1:
case CharacterCodes._2:
case CharacterCodes._3:
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/module/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ namespace ts {
// module is imported only for side-effects, no emit required
break;
}
// falls through

// fall-through
case SyntaxKind.ImportEqualsDeclaration:
Debug.assert(importVariableName !== undefined);
// save import into the local
Expand Down
9 changes: 6 additions & 3 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ namespace ts {
// At this point, node is either a qualified name or an identifier
Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression,
"'node' was expected to be a qualified name, identifier or property access in 'isPartOfTypeNode'.");
// falls through
case SyntaxKind.QualifiedName:
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.ThisKeyword:
Expand Down Expand Up @@ -783,6 +784,7 @@ namespace ts {
if (operand) {
traverse(operand);
}
return;
case SyntaxKind.EnumDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.ModuleDeclaration:
Expand Down Expand Up @@ -1000,7 +1002,7 @@ namespace ts {
if (!includeArrowFunctions) {
continue;
}
// Fall through
// falls through
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ModuleDeclaration:
Expand Down Expand Up @@ -1059,6 +1061,7 @@ namespace ts {
if (!stopOnFunctions) {
continue;
}
// falls through
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.MethodDeclaration:
Expand Down Expand Up @@ -1258,7 +1261,7 @@ namespace ts {
if (node.parent.kind === SyntaxKind.TypeQuery || isJSXTagName(node)) {
return true;
}
// fall through
// falls through
case SyntaxKind.NumericLiteral:
case SyntaxKind.StringLiteral:
case SyntaxKind.ThisKeyword:
Expand Down Expand Up @@ -1940,7 +1943,7 @@ namespace ts {
if (node.asteriskToken) {
flags |= FunctionFlags.Generator;
}
// fall through
// falls through
case SyntaxKind.ArrowFunction:
if (hasModifier(node, ModifierFlags.Async)) {
flags |= FunctionFlags.Async;
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ namespace ts {
nodesVisitor((<UnionOrIntersectionTypeNode>node).types, visitor, isTypeNode));

case SyntaxKind.ParenthesizedType:
Debug.fail("not implemented.");
throw Debug.fail("not implemented.");

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

case SyntaxKind.JsxAttributes:
result = reduceNodes((<JsxAttributes>node).properties, cbNodes, result);
break;

case SyntaxKind.JsxClosingElement:
result = reduceNode((<JsxClosingElement>node).tagName, cbNode, result);
Expand All @@ -1310,7 +1311,7 @@ namespace ts {
// Clauses
case SyntaxKind.CaseClause:
result = reduceNode((<CaseClause>node).expression, cbNode, result);
// fall-through
// falls through

case SyntaxKind.DefaultClause:
result = reduceNodes((<CaseClause | DefaultClause>node).statements, cbNodes, result);
Expand Down Expand Up @@ -1344,6 +1345,7 @@ namespace ts {
case SyntaxKind.EnumMember:
result = reduceNode((<EnumMember>node).name, cbNode, result);
result = reduceNode((<EnumMember>node).initializer, cbNode, result);
break;

// Top-level nodes
case SyntaxKind.SourceFile:
Expand Down
7 changes: 5 additions & 2 deletions src/services/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace ts.BreakpointResolver {
if (isFunctionBlock(node)) {
return spanInFunctionBlock(<Block>node);
}
// Fall through
// falls through
case SyntaxKind.ModuleBlock:
return spanInBlock(<Block>node);

Expand Down Expand Up @@ -186,6 +186,7 @@ namespace ts.BreakpointResolver {
if (getModuleInstanceState(node) !== ModuleInstanceState.Instantiated) {
return undefined;
}
// falls through

case SyntaxKind.ClassDeclaration:
case SyntaxKind.EnumDeclaration:
Expand Down Expand Up @@ -473,6 +474,7 @@ namespace ts.BreakpointResolver {
if (getModuleInstanceState(block.parent) !== ModuleInstanceState.Instantiated) {
return undefined;
}
// falls through

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

case SyntaxKind.EnumDeclaration:
case SyntaxKind.ClassDeclaration:
Expand All @@ -593,7 +596,7 @@ namespace ts.BreakpointResolver {
// Span on close brace token
return textSpan(node);
}
// fall through
// falls through

case SyntaxKind.CatchClause:
return spanInNode(lastOrUndefined((<Block>node.parent).statements));
Expand Down
2 changes: 1 addition & 1 deletion src/services/classifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace ts {
case EndOfLineState.InTemplateMiddleOrTail:
text = "}\n" + text;
offset = 2;
// fallthrough
// falls through
case EndOfLineState.InTemplateSubstitutionPosition:
templateStack.push(SyntaxKind.TemplateHead);
break;
Expand Down
3 changes: 2 additions & 1 deletion src/services/codefixes/importFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ namespace ts.codefix {

switch (this.compareModuleSpecifiers(existingAction.moduleSpecifier, newAction.moduleSpecifier)) {
case ModuleSpecifierComparison.Better:
// the new one is not worth considering if it is a new improt.
// the new one is not worth considering if it is a new import.
// However if it is instead a insertion into existing import, the user might want to use
// the module specifier even it is worse by our standards. So keep it.
if (newAction.kind === "NewImport") {
return;
}
// falls through
case ModuleSpecifierComparison.Equal:
// the current one is safe. But it is still possible that the new one is worse
// than another existing one. For example, you may have new imports from "./foo/bar"
Expand Down
2 changes: 2 additions & 0 deletions src/services/codefixes/unusedIdentifierFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace ts.codefix {
return deleteNodeInList(token.parent);
}
}
// TODO: #14885
// falls through

case SyntaxKind.TypeParameter:
const typeParameters = (<DeclarationWithTypeParameters>token.parent.parent).typeParameters;
Expand Down
Loading