eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

`prefer-set-has`: Add a `minimumItems` array length option

Open omril1 opened this issue 1 year ago • 1 comments

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);

omril1 avatar Oct 28 '24 18:10 omril1

Accepted.

The option should be called minimumItems.

sindresorhus avatar Jan 24 '25 08:01 sindresorhus