unicorn/no-useless-collection-argument Style
What it does โ
Disallow useless values or fallbacks in Set, Map, WeakSet, or WeakMap.
Why is this bad? โ
It is unnecessary to pass an empty array or empty string when constructing a Set, Map, WeakSet, or WeakMap, since they accept nullish values.
It is also unnecessary to provide a fallback for possible nullish values.
Examples โ
Examples of incorrect code for this rule:
js
const set = new Set([]);
const set = new Set("");Examples of correct code for this rule:
js
const set = new Set();Examples of incorrect code for this rule:
js
const set = new Set(foo ?? []);
const set = new Set(foo ?? "");Examples of correct code for this rule:
js
const set = new Set(foo);How to use โ
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/no-useless-collection-argument": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/no-useless-collection-argument": "error",
},
});bash
oxlint --deny unicorn/no-useless-collection-argumentVersion โ
This rule was added in v1.28.0.
