# unicorn/no-useless-collection-argument

> Disallow empty arguments and fallbacks in `new Set()`, `Map`, `WeakSet`, and `WeakMap`

`new Set()`, `new Map()`, `new WeakSet()` and `new WeakMap()` make an empty collection when they get no argument, `undefined` or `null`. So `new Set([])` passes an array for nothing, and the fallback in `new Set(items ?? [])` never changes the result.

The rule reports `[]`, `""`, `null` and `undefined`, either as the only argument or on the right of `??`.

`--fix-suggestions` removes the argument or the fallback.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/no-useless-collection-argument" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```js
const seen = new Set([]);
const cache = new Map(undefined);

function unique(items) {
  return new Set(items ?? []);
}
```

Not reported:

{/* good */}
```js
const seen = new Set();
const cache = new Map();

function unique(items) {
  return new Set(items);
}

const defaults = new Set(items ?? ["all"]);
```
