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.
nursery/useSetMethods
nursery · since 2.6.10
{
"linter": {
"rules": {
"nursery": {
"useSetMethods": "error"
}
}
}
}Prefer Iterator.zip() over parallel-array indexing.
Enforce consistent class references in static methods.
Prefer else if over adjacent if statements with related conditions.
Enforce consistent class member order.
Prefer early continues over conditionals wrapping the remainder of the loop body.
Enforce consistent conditional object spread style.