Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@putout/plugin-logical-expressions
Advanced tools
Readme
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
.
npm i @putout/plugin-logical-expressions -D
{
"rules": {
"logical-expressions/simplify": "on",
"logical-expressions/remove-boolean": "on",
"logical-expressions/remove-duplicates": "on",
"logical-expressions/convert-bitwise-to-logical": "on"
}
}
const is = !(options && !options.bidirectional);
if (!left.type === 'UnaryExpression') {}
const oneOf = a || a;
const same = a === a;
a() && b;
const is = !options || options.bidirectional;
if (left.type !== 'UnaryExpression') {}
const oneOf = a;
const same = true;
a();
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
A boolean is a logical data type that can have only the values
true
orfalse
.(c) MDN
const t = true && false;
const t = false;
const t = a && b && a;
const t = a && b;
The bitwise OR operator (
|
) returns a1
in each bit position for which the corresponding bits of either or both operands are1
s.The operands are converted to 32-bit integers and expressed by a series of bits (zeroes and ones).
(c) MDN
Convert bitwise
to logical
operator, when one of operands is not a number, since mostly likely it is an error.
a | !b;
if (!(a !== b))
fn();
a || !b;
if (a === b)
fn();
Linter | Rule | Fix |
---|---|---|
🐊 Putout | logical-expressions | ✅ |
⏣ ESLint | no-constant-binary-expression | ❌ |
MIT
FAQs
🐊Putout plugin adds ability to transform logical expressions
The npm package @putout/plugin-logical-expressions receives a total of 3,548 weekly downloads. As such, @putout/plugin-logical-expressions popularity was classified as popular.
We found that @putout/plugin-logical-expressions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.