@putout/plugin-simplify-logical-expressions
🐊Putout plugin adds ability to simplify logical expressions
Last updated 4 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/plugin-simplify-logical-expressions 
SYNC missed versions from official npm registry.

@putout/plugin-simplify-logical-expressions NPM version

The logical NOT (!) operator takes truth to falsity and vice versa.

(c) MDN

????Putout plugin adds ability to simplify logical expressions containing comparisons which will always evaluate to true or false since it's likely indications of programmer error. Complements @putout/plugin-apply-comparison-order. Merged to @putout/plugin-logical-expressions.

Install

npm i @putout/plugin-simplify-logical-expressions -D

Rule

{
    "rules": {
        "simplify-logical-expressions": "on"
    }
}

❌ Example of incorrect code

const is = !(options && !options.bidirectional);

if (!left.type === 'UnaryExpression');

const oneOf = a || a;
const same = a === a;

✅ Example of correct code

const is = !options || options.bidirectional;

if (left.type !== 'UnaryExpression');

const oneOf = a;
const same = true;

The rule also simplify duplication use:

-if (a && b || a && c) {
+if (a && (b || c)) {
}

Wrong cases with instanceof:

-!a instanceof b;
-a instanceof !b;
-!a instanceof !b;
+!(a instanceof b);

Wrong cases with in:

-!a in b;
-a in !b;
+!(a in b);

In case of duplicates:

-a && b && a
+a && b

Comparison

Linter Rule Fix
???? Putout simplify-logical-expressions
ESLint no-constant-binary-expression

License

MIT

Current Tags

  • 4.0.2                                ...           latest (4 years ago)

10 Versions

  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.3.0                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (6)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |