For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/unicorn/no-duplicate-set-values.md.
close

no-duplicate-set-values

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-duplicate-set-values': 'error',
    },
  },
]);

Rule Details

Disallow duplicate values in Set constructor array literals.

Set values are unique, so repeated static values in a new Set([...]) array literal are redundant. Values are compared with SameValueZero, the comparison Set uses: NaN matches NaN, 0 matches -0, and an array hole matches undefined. Constant bindings are resolved, while values that could change through getters or mutation are not treated as static.

The rule also reports repeated reference expressions, like foo.bar and foo["bar"]. It does not model mutations or side effects between elements.

Examples of incorrect code:

const set = new Set(['foo', 'bar', 'foo']);

const foo = 2;
const numbers = new Set([foo, 2]);

const references = new Set([foo.bar, foo.bar]);

Examples of correct code:

const set = new Set(['foo', 'bar']);

const foo = 2;
const numbers = new Set([foo, 3]);

const references = new Set([foo.bar, foo.baz]);

This rule only checks new Set([...]) with a single array literal argument, including one wrapped in TypeScript as, satisfies, ! or <Type> assertions. It does not check arrays, maps, non-array iterables, or chained Set#add() calls.

Differences from upstream

Regular expression literals wrapped in TypeScript assertions are not reported. Each literal evaluates to a new object, so the Set keeps both values. Upstream reports the second one:

// Not reported by rslint; reported by upstream.
const patterns = new Set([/a/ as RegExp, /a/ as RegExp]);

A repeated reference to the same regular expression is still reported:

const pattern = /a/;
const patterns = new Set([pattern, pattern]);

Original Documentation