Skip to main content

js/useSimplifiedLogicalExpression

discard redundant terms from logical expressions

Examples

Invalid

const boolExp = true;
const r = true && boolExp;

 file.ts:2:10 lint/js/useSimplifiedLogicalExpression  FIXABLE  ━━━━━━━━━━━━

  Logical expression contains unnecessary complexity.

    1const boolExp = true;
  > 2const r = true && boolExp;
               ^^^^^^^^^^^^^^^

  Safe fix

  - true·&&·boolExp
  + boolExp


const boolExp = true;
const r = boolExp || true;

 file.ts:2:10 lint/js/useSimplifiedLogicalExpression  FIXABLE  ━━━━━━━━━━━━

  Logical expression contains unnecessary complexity.

    1const boolExp = true;
  > 2const r = boolExp || true;
               ^^^^^^^^^^^^^^^

  Safe fix

  - boolExp·||·true
  + true


const nonNullExp = 123;
const r = null ?? nonNullExp;

 file.ts:2:10 lint/js/useSimplifiedLogicalExpression  FIXABLE  ━━━━━━━━━━━━

  Logical expression contains unnecessary complexity.

    1const nonNullExp = 123;
  > 2const r = null ?? nonNullExp;
               ^^^^^^^^^^^^^^^^^^

  Safe fix

  - null·??·nonNullExp
  + nonNullExp


const boolExpr1 = true;
const boolExpr2 = false;
const r = (!boolExpr1) || (!boolExpr2);

 file.ts:3:10 lint/js/useSimplifiedLogicalExpression  FIXABLE  ━━━━━━━━━━━━

  Logical expression contains unnecessary complexity.

    1const boolExpr1 = true;
    2const boolExpr2 = false;
  > 3const r = (!boolExpr1) || (!boolExpr2);
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Safe fix

  - !boolExpr1·||·!boolExpr2
  + !(boolExpr1·&&·boolExpr2)

Valid

const boolExpr1 = true;
const boolExpr2 = false;
const r = !(boolExpr1 && boolExpr2);
const boolExpr1 = true;
const boolExpr2 = false;
const r = (!!boolExpr1 || !!boolExpr2);