{"record":{"id":"5c5b161f8fa25361","repo":"oxc-project/oxc","slug":"empty-fallbacks-in-spreads-are-unnecessary","errorCode":null,"errorMessage":"Empty fallbacks in spreads are unnecessary","messagePattern":"Empty fallbacks in spreads are unnecessary","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs","lineNumber":10,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::operator::LogicalOperator;\n\nuse crate::{AstNode, ast_util::outermost_paren_parent, context::LintContext, rule::Rule};\n\nfn no_useless_fallback_in_spread_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Empty fallbacks in spreads are unnecessary\")\n        .with_help(\"Spreading falsy values in object literals won't add any unexpected properties, so it's unnecessary to add an empty object as fallback.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoUselessFallbackInSpread;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow useless fallback when spreading in object literals.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Spreading [falsy values](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) in object literals won't add any unexpected properties, so it's unnecessary to add an empty object as fallback.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs#L1-L28","documentation":"Diagnostic from the oxlint rule `unicorn/no-useless-fallback-in-spread`. It fires when a spread element inside an object literal uses an empty object as fallback: `{ ...(foo || {}) }` or `{ ...(foo ?? {}) }`. Spreading a falsy value into an object literal adds no properties, so the empty fallback is dead code. The rule is in the correctness category with a conditional autofix that rewrites to `...foo`, applied only when the left side is an identifier, object literal, chain, call, or member expression (not `undefined`, `NaN`, or `Infinity`).","triggerScenarios":"`const object = { ...(foo || {}) }`, `{ ...(foo ?? {}) }`, nested-paren forms `{ ...((( foo )) ?? (( {} ))) }`, and `async () => ({ ...((await foo) || {}) })`. Only `||` and `??` with an empty object literal on the right, only inside object-literal spreads; `[...(foo || [])]` and `{ ...(foo || { not: 'empty' }) }` do not trigger it.","commonSituations":"Merging props or options objects, e.g. React spread patterns `{...(props || {})}`, and code migrated from older null-guarded styles. Hits projects that enable oxlint's correctness category or the unicorn plugin.","solutions":["Drop the fallback: `{ ...(foo || {}) }` -> `{ ...foo }`.","Apply the rule's autofix when the left side is fixable (identifier, member, or call expression).","If the goal is to supply defaults, use a non-empty fallback object with real keys.","For intentional cases (for example left side `NaN`), add an inline `oxlint-disable-next-line unicorn/no-useless-fallback-in-spread` comment."],"exampleFix":"// before\nconst object = { ...(foo || {}) };\n\n// after\nconst object = { ...foo };","handlingStrategy":"validation","validationCode":"# detect ...(x || {}) / ...(x ?? {}) in object spreads\nrg -n --type js -U '\\.\\.\\.\\s*\\([^)]*?\\s*(?:\\|\\||\\?\\?)\\s*\\{\\s*\\}' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Spread nullable values directly in object literals; falsy spreads are no-ops in JS.","Reserve fallback objects for shapes that carry real default keys.","Add the rule to your oxlint config as correctness so regressions fail CI."],"tags":["lint","oxlint","unicorn","spread","object-literal","dead-code","correctness"],"backgroundTag":"useless-fallback-in-spread","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"}