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-conditions
Advanced tools
Readme
🐊Putout adds support of conditions transformations.
npm i @putout/plugin-conditions -D
{
"rules": {
"conditions/apply-consistent-blocks": "on",
"conditions/apply-comparison-order": "on",
"conditions/apply-if": "on",
"conditions/add-return": "on",
"conditions/convert-comparison-to-boolean": "on",
"conditions/convert-equal-to-strict-equal": "on",
"conditions/evaluate": "on",
"conditions/remove-boolean": "on",
"conditions/remove-constant": "on",
"conditions/remove-zero": "on",
"conditions/remove-useless-else": "on",
"conditions/remove-same-values-condition": "on",
"conditions/merge-if-statements": "on"
}
}
A block statement is used to group zero or more statements. The block is delimited by a pair of braces ("curly braces") and contains a list of zero or more statements and declarations.
(c) MDN
Check out in 🐊Putout Editor.
if (a > 3) {
m();
}
if (a > 3)
b = 5;
else {
b = 6;
}
if (a > 3)
b = 5;
else {
b = 6;
fn();
}
if (a > 3)
m();
if (a > 3)
b = 5;
else
b = 6;
if (a > 3) {
b = 5;
} else {
b = 6;
fn();
}
The result of evaluating an equality operator is always of type boolean based on whether the comparison is true.
(c) MDN
Checkout it 🐊Putout Editor.
3 === a;
3 < b;
a === 3;
b > 3;
Linter | Rule | Fix |
---|---|---|
🐊 Putout | conditions/apply-comparison-order | ✅ |
⏣ ESLint | yoda | ½ |
if (2 > 3)
;
alert();
if (2 > 3)
alert();
Checkout in 🐊Putout Editor.
if (a)
false;
if (a)
return false;
Strict equality compares two values for equality. Neither value is implicitly converted to some other value before being compared. If the values have different types, the values are considered unequal.
(c) MDN
const t = 2 < 3;
const t = false;
The strict equality operator (
===
) checks whether its two operands are equal, returning aBoolean
result. Unlike the equality operator (==
), the strict equality operator always considers operands of different types to be different.(c) MDN
if (a == b) {}
if (a === b) {}
The if statement executes a statement if a specified condition is truthy. If the condition is falsy, another statement can be executed.
(c) MDN
const a = [];
const c = a;
if (a)
console.log(a);
const a = [];
const c = a;
console.log(a);
if (a === true)
alert();
if (a)
alert();
function hi(a) {
if (2 < 3) {
console.log('hello');
console.log('world');
}
}
function hi(b) {
console.log('hello');
console.log('world');
}
if (b === 0) {}
if (b !== 0) {}
if (!b) {}
if (b) {}
if (zone?.tooltipCallback)
zone.tooltipCallback(e);
if (a)
alert('hello');
else
alert('hello');
zone?.tooltipCallback(e);
alert('hello');
The
if
statement executes a statementif
a specified condition is truthy.(c) MDN
if (a > b)
if (b < c)
console.log('hello');
if (a > b && b < c)
console.log('hello');
You can skip the
else
block if yourif
block always executes areturn
statement, it makes code a lot easier to read.(c) no else return
Remove useless else
before:
return
;continue
;break
;if (x)
return;
else
console.log();
if (x)
return;
console.log();
Checkout in 🐊Putout Editor.
for (const [i, el] of entries(elements)) {
if (el !== path)
continue;
if (!Number(i) && n) {
path.parentPath.node.elements[i] = null;
break;
}
if (el === path) {
remove(path);
break;
}
}
for (const [i, el] of entries(elements)) {
if (el !== path)
continue;
if (!Number(i) && n) {
path.parentPath.node.elements[i] = null;
break;
}
remove(path);
}
Linter | Rule | Fix |
---|---|---|
🐊 Putout | conditions/remove-useless-else | ✅ |
⏣ ESLint | no-else-return | ✅ |
MIT
FAQs
🐊Putout plugin adds support of conditions transformations
The npm package @putout/plugin-conditions receives a total of 3,299 weekly downloads. As such, @putout/plugin-conditions popularity was classified as popular.
We found that @putout/plugin-conditions 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.