From 2aba847f23f459fa1d8bf1997ee88fbe4be372bc Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Thu, 19 Jan 2017 23:15:15 -0500 Subject: [PATCH] Make `strict-boolean-expressions` test consistent w/ ts 2.0 (#2082) --- src/rules/strictBooleanExpressionsRule.ts | 2 +- .../strict-boolean-expressions/default/test.ts.lint | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rules/strictBooleanExpressionsRule.ts b/src/rules/strictBooleanExpressionsRule.ts index a00c809af12..e48e0a84ff0 100644 --- a/src/rules/strictBooleanExpressionsRule.ts +++ b/src/rules/strictBooleanExpressionsRule.ts @@ -348,7 +348,7 @@ function stringOr(parts: string[]): string { } function isUnionType(type: ts.Type): type is ts.UnionType { - return Lint.isTypeFlagSet(type, ts.TypeFlags.Union); + return Lint.isTypeFlagSet(type, ts.TypeFlags.Union) && !Lint.isTypeFlagSet(type, ts.TypeFlags.Enum); } declare module "typescript" { diff --git a/test/rules/strict-boolean-expressions/default/test.ts.lint b/test/rules/strict-boolean-expressions/default/test.ts.lint index 8c1ebe087ad..17d3f2ede85 100644 --- a/test/rules/strict-boolean-expressions/default/test.ts.lint +++ b/test/rules/strict-boolean-expressions/default/test.ts.lint @@ -28,7 +28,7 @@ boolType && strType; ~~~~~~~ [This type is not allowed in the operand for the '&&' operator because it is a string. Only booleans are allowed.] boolType && objType && enumType; ~~~~~~~ [This type is not allowed in the operand for the '&&' operator because it is always truthy. Only booleans are allowed.] - ~~~~~~~~ [This type is not allowed in the operand for the '&&' operator because it could be an enum. Only booleans are allowed.] + ~~~~~~~~ [This type is not allowed in the operand for the '&&' operator because it is an enum. Only booleans are allowed.] bwrapType && boolType; ~~~~~~~~~ [This type is not allowed in the operand for the '&&' operator because it is always truthy. Only booleans are allowed.] @@ -44,7 +44,7 @@ bwrapType || boolType; ~~~~~~~~~ [This type is not allowed in the operand for the '||' operator because it is always truthy. Only booleans are allowed.] objType || boolType || enumType; ~~~~~~~ [This type is not allowed in the operand for the '||' operator because it is always truthy. Only booleans are allowed.] - ~~~~~~~~ [This type is not allowed in the operand for the '||' operator because it could be an enum. Only booleans are allowed.] + ~~~~~~~~ [This type is not allowed in the operand for the '||' operator because it is an enum. Only booleans are allowed.] boolExpr && strType; ~~~~~~~ [This type is not allowed in the operand for the '&&' operator because it is a string. Only booleans are allowed.] @@ -78,7 +78,7 @@ classType ? strType : undefined; bwrapType ? 1 : 0; ~~~~~~~~~ [This type is not allowed in the condition because it is always truthy. Only booleans are allowed.] enumType ? 0 : 1; -~~~~~~~~ [This type is not allowed in the condition because it could be an enum. Only booleans are allowed.] +~~~~~~~~ [This type is not allowed in the condition because it is an enum. Only booleans are allowed.] /*** Valid ***/ boolFn() ? numType : strType; @@ -93,7 +93,7 @@ boolType ? strType : undefined; !objType; ~~~~~~~ [This type is not allowed in the operand for the '!' operator because it is always truthy. Only booleans are allowed.] !enumType; - ~~~~~~~~ [This type is not allowed in the operand for the '!' operator because it could be an enum. Only booleans are allowed.] + ~~~~~~~~ [This type is not allowed in the operand for the '!' operator because it is an enum. Only booleans are allowed.] !!classType; ~~~~~~~~~ [This type is not allowed in the operand for the '!' operator because it is always truthy. Only booleans are allowed.] !bwrapType; @@ -178,4 +178,4 @@ do { /* statements */ } while (boolType); for (let j = 0; j; j++) { /* statements */ } ~ [This type is not allowed in the 'for' condition because it is a number. Only booleans are allowed.] /*** Valid ***/ -for (let j = 0; j > numType; j++) { /* statements */ } \ No newline at end of file +for (let j = 0; j > numType; j++) { /* statements */ }