10000 fix(eslint-plugin): [strict-bool-expr] allow nullish coalescing (#1275) · lipis/typescript-eslint@3b39340 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b39340

Browse files
authored
fix(eslint-plugin): [strict-bool-expr] allow nullish coalescing (typescript-eslint#1275)
1 parent ebf5e0a commit 3b39340

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/eslint-plugin/src/rules/strict-boolean-expressions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export default util.createRule<Options, 'strictBooleanExpression'>({
150150
ForStatement: assertTestExpressionContainsBoolean,
151151
IfStatement: assertTestExpressionContainsBoolean,
152152
WhileStatement: assertTestExpressionContainsBoolean,
153-
LogicalExpression: assertLocalExpressionContainsBoolean,
153+
'LogicalExpression[operator!="??"]': assertLocalExpressionContainsBoolean,
154154
'UnaryExpression[operator="!"]': assertUnaryExpressionContainsBoolean,
155155
};
156156
},

packages/eslint-plugin/tests/rules/strict-boolean-expressions.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ ruleTester.run('strict-boolean-expressions', rule, {
159159
{
160160
options: [{ ignoreRhs: true }],
161161
code: `
162-
const obj = {};
163-
const bool = false;
164-
const boolOrObj = bool || obj;
165-
const boolAndObj = bool && obj;
166-
`,
162+
const obj = {};
163+
const bool = false;
164+
const boolOrObj = bool || obj;
165+
const boolAndObj = bool && obj;
166+
`,
167167
},
168168
{
169169
options: [{ allowNullable: true }],
@@ -174,6 +174,10 @@ const boolAndObj = bool && obj;
174174
const f4 = (x?: false) => x ? 1 : 0;
175175
`,
176176
},
177+
`
178+
declare const x: string | null;
179+
y = x ?? 'foo';
180+
`,
177181
],
178182

179183
invalid: [

0 commit comments

Comments
 (0)
0