unicorn/prefer-set-methods
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-set-methods": "error",
},
},
];const union = new Set([...set, ...otherSet]);const intersection = [...set].filter(value => otherSet.has(value));const difference = [...set].filter(value => !otherSet.has(value));const union = set.union(otherSet);const intersection = set.intersection(otherSet);const difference = set.difference(otherSet);Examples from the ESLint documentation.
unicorn/prefer-set-methods
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-set-methods": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer :scope when using element query selector methods.
Prefer simple conditions first in logical expressions.
Prefer RegExp#exec() over String#match() for non-global regular expressions.
Prefer a single object destructuring declaration per local const source.
Prefer Promise.try() over promise-wrapping boilerplate.
Prefer declaring variables and type aliases in the smallest possible scope.