prefer-set-size

March 27, 2026 ยท View on GitHub

๐Ÿ“ Prefer using Set#size instead of Array#length.

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

Prefer using Set#size directly instead of first converting it to an array and then using its .length property.

Examples

// โŒ
function isUnique(array) {
	return [...new Set(array)].length === array.length;
}

// โœ…
function isUnique(array) {
	return new Set(array).size === array.length;
}