sindresorhus/eslint-plugin-unicorn

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

Open

#2,491 创建于 2024年10月28日

在 GitHub 查看
 (1 评论) (2 反应) (0 负责人)JavaScript (5,022 star) (468 fork)user submission
enhancementhelp wanted

描述

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

贡献者指南

`prefer-set-has`: Add a `minimumItems` array length option · sindresorhus/eslint-plugin-unicorn#2491 | Good First Issue