Skip to content

unicorn/prefer-set-size Correctness

This rule is turned on by default.
🛠️ An auto-fix is available for this rule.

What it does

Prefer Set#size over Set#length when the Set is converted to an array.

Why is this bad?

Using Set#size is more readable and performant.

Examples

Examples of incorrect code for this rule:

javascript
const length = [...new Set([1, 2, 3])].length;

Examples of correct code for this rule:

javascript
const size = new Set([1, 2, 3]).size;

References

Released under the MIT License.