{"record":{"id":"851a06ba02bab0df","repo":"oxc-project/oxc","slug":"the-expr-type-is-useless","errorCode":null,"errorMessage":"The {expr_type} is useless","messagePattern":"The (.+?) is useless","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_useless_collection_argument.rs","lineNumber":20,"sourceCode":"    AstKind,\n    ast::{Expression, LogicalExpression, NewExpression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode,\n    ast_util::is_new_expression,\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    rule::Rule,\n    utils::is_empty_array_expression,\n};\n\nfn no_useless_collection_argument_diagnostic(span: Span, expr_type: &str) -> OxcDiagnostic {\n    let message = format!(\"The {expr_type} is useless\");\n    OxcDiagnostic::warn(message).with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoUselessCollectionArgument;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow useless values or fallbacks in `Set`, `Map`, `WeakSet`, or `WeakMap`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// It is unnecessary to pass an empty array or empty string when\n    /// constructing a `Set`, `Map`, `WeakSet`, or `WeakMap`, since\n    /// they accept nullish values.\n    ///\n    /// It is also unnecessary to provide a fallback for possible nullish values.\n    ///","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_useless_collection_argument.rs#L2-L38","documentation":"Diagnostic from the oxlint rule `unicorn/no-useless-collection-argument`. It fires when `new Set`, `new Map`, `new WeakSet`, or `new WeakMap` is constructed with exactly one argument that is an empty array, an empty string, `null`, or `undefined`, or a `foo ?? <such value>` coalesce fallback. These constructors accept nullish input, so the argument or fallback does nothing. The message fills `{expr_type}` with 'empty array', 'empty string', 'null', or 'undefined', and a suggestion fix removes the useless code.","triggerScenarios":"`new Set([])`, `new Set('')`, `new Map(null)`, `new Set(undefined)`, `new WeakSet([])` with exactly one argument (extra arguments disable the check), plus fallback forms `new Set(foo ?? [])`, `new Map(foo ?? '')`, `new Set(foo ?? null)`, `new Set(foo ?? bar ?? [])`, and parenthesized variants like `new Set((([])))`. Not fired for `new Set(foo || [])`, non-empty strings, or `new globalThis.Set([])`.","commonSituations":"Defensive code written against APIs that throw on nullish input, leftovers after refactoring a producer to always return an iterable, and copy-paste of older fallback patterns. Surfaces when enabling the unicorn plugin or the oxlint style category.","solutions":["Remove the useless argument or fallback: `new Set(foo ?? [])` -> `new Set(foo)`, `new Set([])` -> `new Set()`.","Apply the rule's suggestion fix via `oxlint --fix-suggestions` or your editor quick fix.","If you need default entries, keep a non-empty fallback: `new Set(foo ?? [defaultItem])`.","Keep `|| []` when you truly want an empty collection for every falsy value; the rule only flags `??` fallbacks."],"exampleFix":"// before\nconst set = new Set(foo ?? []);\n\n// after\nconst set = new Set(foo);","handlingStrategy":"validation","validationCode":"# detect useless Set/Map/WeakSet/WeakMap arguments before linting\nrg -n --type js 'new (?:Weak)?(?:Set|Map)\\(\\s*(?:\\[\\s*\\]|\\'\\'|\"\"|null|undefined|[^)]*\\?\\?\\s*(?:\\[\\s*\\]|\\'\\'|null|undefined))' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember the collection constructors accept nullish and iterable input; never add an empty-literal guard.","Use `?? fallback` only with non-empty fallback iterables when defaults are truly needed.","Let `oxlint --fix-suggestions` clean these up mechanically in CI."],"tags":["lint","oxlint","unicorn","set","map","weakmap","dead-code","style"],"backgroundTag":"useless-collection-argument","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}