sindresorhus/eslint-plugin-unicorn
`prefer-set-has`: Add a `minimumItems` array length option
Geschlossen
#2.491 geöffnet am 28.10.2024
enhancementhelp wanted
Repository-Metriken
- Stars
- (5.022 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 4h 30m) (26 gemergte PRs in 30 T)
Beschreibung
Description
Add a minimumItems option so only arrays from a certain known size will be linted (default 0).
The rule can sometimes be too strict, using sets over arrays is usually more performant the more elements it has, and it's negligible in small numbers and readability is preferred.
Fail
minimumItems: 5
const array = [1, 2, 3, 4, 5, 6, 7];
const hasValue = value => array.includes(value);
Pass
minimumItems: 5
const array = [1, 2];
const hasValue = value => array.includes(value);