{"record":{"id":"50783ec9b5de6fc5","repo":"oxc-project/oxc","slug":"do-not-assign-a-property-immediately-after-initial","errorCode":null,"errorMessage":"Do not assign a property immediately after initializing an object literal.","messagePattern":"Do not assign a property immediately after initializing an object literal\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_immediate_mutation.rs","lineNumber":31,"sourceCode":"\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\nfn map_set_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not call `.set()` immediately after initializing a Map.\")\n        .with_help(\"Add the entry to the Map initializer array.\")\n        .with_label(span)\n}\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_immediate_mutation.rs#L13-L49","documentation":"Diagnostic from the oxlint rule `unicorn/no-immediate-mutation` (property arm, category: pedantic). `const state = {}; state.loading = true;` splits an object literal across two statements; the property belongs in the initializer. Only plain `=` assignments to a static (or non-self-referencing computed) member of the same identifier that was declared as an object literal in the immediately preceding statement are flagged; compound assigns (`+=`), chained assignments through the object, and other receivers pass.","triggerScenarios":"`const state = {}; state.loading = true;`, `const obj = { foo: 1 }; obj[key] = value;` — a simple member assignment whose object is the just-declared object literal.","commonSituations":"'Create empty object, then fill it in' habits; partial refactors from classes/functions to object literals; state objects built field by field.","solutions":["Move the property into the literal: `const state = { loading: true };`","For conditional properties use spread: `const state = { ...(active ? { active } : {}) }`","Suppress with `// oxlint-disable-next-line unicorn/no-immediate-mutation` when the split form is intentional"],"exampleFix":"// before\nconst state = {};\nstate.loading = true;\n\n// after\nconst state = { loading: true };","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write complete object literals; add conditional properties with spread","Avoid the declare-empty-then-fill habit for objects with known shape","When a property truly cannot be in the literal, add a comment saying why"],"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-14T05:17:10.506Z"}