Skip to content

Commit

Permalink
fix(eslint-plugin): [strict-bool-expr] allow nullish coalescing (#1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Nov 28, 2019
1 parent ebf5e0a commit 3b39340
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Expand Up @@ -150,7 +150,7 @@ export default util.createRule<Options, 'strictBooleanExpression'>({
ForStatement: assertTestExpressionContainsBoolean,
IfStatement: assertTestExpressionContainsBoolean,
WhileStatement: assertTestExpressionContainsBoolean,
LogicalExpression: assertLocalExpressionContainsBoolean,
'LogicalExpression[operator!="??"]': assertLocalExpressionContainsBoolean,
'UnaryExpression[operator="!"]': assertUnaryExpressionContainsBoolean,
};
},
Expand Down
Expand Up @@ -159,11 +159,11 @@ ruleTester.run('strict-boolean-expressions', rule, {
{
options: [{ ignoreRhs: true }],
code: `
const obj = {};
const bool = false;
const boolOrObj = bool || obj;
const boolAndObj = bool && obj;
`,
const obj = {};
const bool = false;
const boolOrObj = bool || obj;
const boolAndObj = bool && obj;
`,
},
{
options: [{ allowNullable: true }],
Expand All @@ -174,6 +174,10 @@ const boolAndObj = bool && obj;
const f4 = (x?: false) => x ? 1 : 0;
`,
},
`
declare const x: string | null;
y = x ?? 'foo';
`,
],

invalid: [
Expand Down

0 comments on commit 3b39340

Please sign in to comment.