useSimplifiedLogicExpression
诊断类别:lint/complexity/useSimplifiedLogicExpression
¥Diagnostic Category: lint/complexity/useSimplifiedLogicExpression
自从:v1.0.0
¥Since: v1.0.0
从逻辑表达式中丢弃冗余术语。
¥Discard redundant terms from logical expressions.
¥Examples
¥Invalid
code-block.js:2:11 lint/complexity/useSimplifiedLogicExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Logical expression contains unnecessary complexity.
1 │ const boolExp = true;
> 2 │ const r = true && boolExp;
│ ^^^^^^^^^^^^^^^
3 │
ℹ Unsafe fix: Discard redundant terms from the logical expression.
2 │ const·r·=·true·&&·boolExp;
│ --------
code-block.js:2:12 lint/complexity/useSimplifiedLogicExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Logical expression contains unnecessary complexity.
1 │ const boolExp2 = true;
> 2 │ const r2 = boolExp || true;
│ ^^^^^^^^^^^^^^^
3 │
ℹ Unsafe fix: Discard redundant terms from the logical expression.
2 │ const·r2·=·boolExp·||·true;
│ -----------
code-block.js:2:12 lint/complexity/useSimplifiedLogicExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Logical expression contains unnecessary complexity.
1 │ const nonNullExp = 123;
> 2 │ const r3 = null ?? nonNullExp;
│ ^^^^^^^^^^^^^^^^^^
3 │
ℹ Unsafe fix: Discard redundant terms from the logical expression.
2 │ const·r3·=·null·??·nonNullExp;
│ --------
code-block.js:3:12 lint/complexity/useSimplifiedLogicExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Logical expression contains unnecessary complexity.
1 │ const boolExpr1 = true;
2 │ const boolExpr2 = false;
> 3 │ const r4 = !boolExpr1 || !boolExpr2;
│ ^^^^^^^^^^^^^^^^^^^^^^^^
4 │
ℹ Unsafe fix: Reduce the complexity of the logical expression.
1 1 │ const boolExpr1 = true;
2 2 │ const boolExpr2 = false;
3 │ - const·r4·=·!boolExpr1·||·!boolExpr2;
3 │ + const·r4·=·!(boolExpr1·&&·boolExpr2);
4 4 │
¥Valid
¥Related links