sindresorhus/eslint-plugin-unicorn
Rule proposal: No multiple array check in logical expression
Closed
#2,366 opened on May 23, 2024
help wantednew rule
Repository metrics
- Stars
- (5,022 stars)
- PR merge metrics
- (Avg merge 1d 16h) (399 merged PRs in 30d)
Description
Description
Use .some() or .every() check on one array repeatly can simplify to use one call.
Fail
if (
array.some(element => element.foo === 1)
|| array.some(element => element.bar === 2)
) {}
if (
array.every(element => element.foo === 1)
&& array.every(element => element.bar === 2)
) {}
Pass
if (
array.some(element => element.foo === 1 || element.bar === 2)
) {}
if (
array.every(element => element.foo === 1 && element.bar === 2)
) {}
Proposed rule name
Not sure about the name yet
Additional Info
No response