{"record":{"id":"adb123de9b56097e","repo":"oxc-project/oxc","slug":"do-not-call-object-assign-immediately-after-in","errorCode":null,"errorMessage":"Do not call `Object.assign()` immediately after initializing an object.","messagePattern":"Do not call `Object\\.assign\\(\\)` immediately after initializing an object\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_immediate_mutation.rs","lineNumber":25,"sourceCode":"    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::IsGlobalReference;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn array_mutation_diagnostic(span: Span, method: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"Do not call `{method}()` immediately after initializing an array.\"\n    ))\n    .with_help(format!(\"Move the elements from `{method}()` into the array initializer.\"))\n    .with_label(span)\n}\n\nfn object_assign_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not call `Object.assign()` immediately after initializing an object.\")\n        .with_help(\"Move the properties from `Object.assign()` into the object initializer.\")\n        .with_label(span)\n}\n\nfn object_property_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Do not assign a property immediately after initializing an object literal.\",\n    )\n    .with_help(\"Move the property into the object initializer.\")\n    .with_label(span)\n}\n\nfn set_add_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not call `.add()` immediately after initializing a Set.\")\n        .with_help(\"Add the element to the Set initializer array.\")\n        .with_label(span)\n}\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_immediate_mutation.rs#L7-L43","documentation":"Diagnostic from the oxlint rule `unicorn/no-immediate-mutation` (Object.assign arm, category: pedantic). Declaring an object literal and immediately merging into it with the global `Object.assign(obj, ...)` is a two-step initialization; the rule wants the object built once, via object spread or literal properties. It fires only when the call directly follows the declaration of the same object-literal variable, has at least two arguments, the second is not a spread, and no argument references the variable itself.","triggerScenarios":"`const config = {}; Object.assign(config, defaults);` or `const obj = { foo: 1 }; Object.assign(obj, { bar: 2 });` — the first argument is the identifier declared as an object literal in the immediately preceding statement. `Object.assign(obj, ...spread)` sources and self-references pass.","commonSituations":"Config/option merging written before spread syntax was available; older transpiled output; incremental construction leftovers in initialization paths.","solutions":["Initialize once with spread: `const config = { ...defaults, debug: true };`","For computed keys use `{ ...base, [key]: value }`","If the assign target is reused later and the merge must stay, restructure or suppress inline"],"exampleFix":"// before\nconst config = {};\nObject.assign(config, defaults, { debug: true });\n\n// after\nconst config = { ...defaults, debug: true };","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer object spread over Object.assign for building new objects","Reserve Object.assign for patching existing targets that cannot be rebuilt","Treat init-then-assign pairs as a refactor signal in review"],"tags":["objects","style","code-quality","oxlint"],"backgroundTag":"mutate-after-init","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}