diff --git a/src/rules/noUnusedExpressionRule.ts b/src/rules/noUnusedExpressionRule.ts index 20c2ca733c6..446d46367ba 100644 --- a/src/rules/noUnusedExpressionRule.ts +++ b/src/rules/noUnusedExpressionRule.ts @@ -38,17 +38,17 @@ class NoUnusedExpressionWalker extends Lint.RuleWalker { this.expressionIsUnused = true; super.visitExpressionStatement(node); if (this.expressionIsUnused) { - // ignore valid unused expressions - if (node.expression.kind === ts.SyntaxKind.StringLiteral) { - const expressionText = node.expression.getText(); - if (expressionText === "\"use strict\"" || expressionText === "'use strict'") { - return; - } - } else if (node.expression.kind === ts.SyntaxKind.DeleteExpression || node.expression.kind === ts.SyntaxKind.YieldExpression) { - return; - } + const { expression } = node; + const { kind } = expression; + const isValidStandaloneExpression = kind === ts.SyntaxKind.DeleteExpression + || kind === ts.SyntaxKind.YieldExpression + || kind === ts.SyntaxKind.AwaitExpression; + const isValidStringExpression = kind === ts.SyntaxKind.StringLiteral + && (expression.getText() === '"use strict"' || expression.getText() === "'use strict'"); - this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING)); + if (!isValidStandaloneExpression && !isValidStringExpression) { + this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING)); + } } } diff --git a/test/files/rules/unused.expression.test.ts b/test/files/rules/unused.expression.test.ts index 87f87bf73ad..ab886b1d121 100644 --- a/test/files/rules/unused.expression.test.ts +++ b/test/files/rules/unused.expression.test.ts @@ -53,3 +53,8 @@ function* g(): Iterable { yield i; } } + +async function f(foo: Promise): Promise { + await foo; + return 0; +} diff --git a/tslint.json b/tslint.json index 45e6d99d1b7..f2868238e95 100644 --- a/tslint.json +++ b/tslint.json @@ -48,7 +48,7 @@ "check-else", "check-whitespace" ], - "quotemark": [true, "double"], + "quotemark": [true, "double", "avoid-escape"], "radix": true, "semicolon": true, "triple-equals": [true, "allow-null-check"],