sindresorhus/eslint-plugin-unicorn
Rule proposal: No multiple array check in logical expression
Chiusa
#2366 aperta il 23 mag 2024
help wantednew rule
Metriche repository
- Star
- (5022 stelle)
- Metriche merge PR
- (Merge medio 4h 30m) (26 PR mergiate in 30 g)
Descrizione
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