From 96131573392fdb8d99acd1fb4edf94d994b05fb5 Mon Sep 17 00:00:00 2001 From: rrogowski Date: Tue, 26 Mar 2019 10:08:44 -0400 Subject: [PATCH] allow conditional expressions --- src/rules/noVoidExpressionRule.ts | 4 ++++ test/rules/no-void-expression/default/test.ts.lint | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/rules/noVoidExpressionRule.ts b/src/rules/noVoidExpressionRule.ts index 798924dd4b6..ff1b0f87752 100644 --- a/src/rules/noVoidExpressionRule.ts +++ b/src/rules/noVoidExpressionRule.ts @@ -104,6 +104,10 @@ function walk(ctx: Lint.WalkContext, checker: ts.TypeChecker): void { // Something like "x && console.log(x)". case ts.SyntaxKind.BinaryExpression: return isParentAllowedVoid(node.parent); + + // Something like "!!cond ? console.log(true) : console.log(false)" + case ts.SyntaxKind.ConditionalExpression: + return true; default: return false; } diff --git a/test/rules/no-void-expression/default/test.ts.lint b/test/rules/no-void-expression/default/test.ts.lint index 663fe260c75..1322aff7aee 100644 --- a/test/rules/no-void-expression/default/test.ts.lint +++ b/test/rules/no-void-expression/default/test.ts.lint @@ -24,4 +24,6 @@ declare function doIt(): void; declare function doAsync(): Promise; declare function print(strs: TemplateStringsArray): void; +!!data ? console.info(message, data) : console.info(message); + [0]: Expression has type `void`. Put it on its own line as a statement.