eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
Rule proposal: `no-negated-some-every`
Description
I believe all negative Array.every()
can write in positive Array.some()
[
![].every(() => true) === [].some(() => !true),
![0].every(() => true) === [0].some(() => !true),
![1].every(() => true) === [1].some(() => !true),
![].every(() => false) === [].some(() => !false),
![0].every(() => false) === [0].some(() => !false),
![1].every(() => false) === [1].some(() => !false),
]
Fail
if (!array.some(element => test(element)));
if (!array.every(element => test(element)));
Pass
if (array.every(element => !test(element)));
if (array.some(element => !test(element)));
if (!array.every(Boolean));
Extra
I'm not sure about this, maybe only simple cases?
if (
!array.some(element => {
if (foo) {
return true;
}
if (bar) {
return false;
}
return baz;
})
);
I remember we have a rule proposal to prevent unnecessary negated condition, but I forget what's in that proposal and I can't find it.
I remember we have a rule proposal to prevent unnecessary negated condition, but I forget what's in that proposal and I can't find it.
https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1073 ?
Not this one, I'll search issues again.
This #856. Kind of related, but this is more complicated.
I believe all negative
Array.every()
can write in positiveArray.some()
They can, but I think it might worsen readability sometimes.
They can, but I think it might worsen readability sometimes.
Example?
Accepted