From 4683cb5bada7ebd5c804963e1d76417835cff4e1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 29 May 2018 09:06:16 -0700 Subject: [PATCH 1/2] Add assertions --- scripts/tslint/rules/nextLineRule.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tslint/rules/nextLineRule.ts b/scripts/tslint/rules/nextLineRule.ts index fa03746afc6..9de80793c62 100644 --- a/scripts/tslint/rules/nextLineRule.ts +++ b/scripts/tslint/rules/nextLineRule.ts @@ -52,8 +52,8 @@ function walk(ctx: Lint.WalkContext, checkCatch: boolean, checkElse: boole return; } - const tryClosingBrace = tryBlock.getLastToken(sourceFile); - const catchKeyword = catchClause.getFirstToken(sourceFile); + const tryClosingBrace = tryBlock.getLastToken(sourceFile)!; + const catchKeyword = catchClause.getFirstToken(sourceFile)!; const tryClosingBraceLoc = sourceFile.getLineAndCharacterOfPosition(tryClosingBrace.getEnd()); const catchKeywordLoc = sourceFile.getLineAndCharacterOfPosition(catchKeyword.getStart(sourceFile)); if (tryClosingBraceLoc.line === catchKeywordLoc.line) { From 94c455792aaee5f77308ac9307530a5995d234f9 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 29 May 2018 09:06:35 -0700 Subject: [PATCH 2/2] Remove unneeded assertions --- scripts/tslint/rules/noInOperatorRule.ts | 2 +- scripts/tslint/rules/noIncrementDecrementRule.ts | 4 ++-- src/services/documentHighlights.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tslint/rules/noInOperatorRule.ts b/scripts/tslint/rules/noInOperatorRule.ts index 448cf90cacd..95f052ccaa6 100644 --- a/scripts/tslint/rules/noInOperatorRule.ts +++ b/scripts/tslint/rules/noInOperatorRule.ts @@ -12,7 +12,7 @@ export class Rule extends Lint.Rules.AbstractRule { function walk(ctx: Lint.WalkContext): void { ts.forEachChild(ctx.sourceFile, recur); function recur(node: ts.Node): void { - if (node.kind === ts.SyntaxKind.InKeyword && node.parent!.kind === ts.SyntaxKind.BinaryExpression) { + if (node.kind === ts.SyntaxKind.InKeyword && node.parent.kind === ts.SyntaxKind.BinaryExpression) { ctx.addFailureAtNode(node, Rule.FAILURE_STRING); } } diff --git a/scripts/tslint/rules/noIncrementDecrementRule.ts b/scripts/tslint/rules/noIncrementDecrementRule.ts index ff2d81b1962..007d25919e1 100644 --- a/scripts/tslint/rules/noIncrementDecrementRule.ts +++ b/scripts/tslint/rules/noIncrementDecrementRule.ts @@ -28,7 +28,7 @@ function walk(ctx: Lint.WalkContext): void { } function check(node: ts.UnaryExpression): void { - if (!isAllowedLocation(node.parent!)) { + if (!isAllowedLocation(node.parent)) { ctx.addFailureAtNode(node, Rule.POSTFIX_FAILURE_STRING); } } @@ -47,7 +47,7 @@ function isAllowedLocation(node: ts.Node): boolean { // Can be in a comma operator in a for statement (`for (let a = 0, b = 10; a < b; a++, b--)`) case ts.SyntaxKind.BinaryExpression: return (node as ts.BinaryExpression).operatorToken.kind === ts.SyntaxKind.CommaToken && - node.parent!.kind === ts.SyntaxKind.ForStatement; + node.parent.kind === ts.SyntaxKind.ForStatement; default: return false; diff --git a/src/services/documentHighlights.ts b/src/services/documentHighlights.ts index e6a78e098e9..afae01e0c68 100644 --- a/src/services/documentHighlights.ts +++ b/src/services/documentHighlights.ts @@ -180,7 +180,7 @@ namespace ts.DocumentHighlights { default: // Don't cross function boundaries. // TODO: GH#20090 - return (isFunctionLike(node) && "quit") as false | "quit"; + return isFunctionLike(node) && "quit"; } }); }