{"record":{"id":"48cae1340dcf39fd","repo":"oxc-project/oxc","slug":"unexpected-operator-assignment-operator-shorth","errorCode":null,"errorMessage":"Unexpected operator assignment ({operator}) shorthand.","messagePattern":"Unexpected operator assignment \\((.+?)\\) shorthand\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/operator_assignment.rs","lineNumber":33,"sourceCode":"use crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::{AlwaysNever, is_same_member_expression},\n};\n\nfn operator_assignment_diagnostic(\n    mode: &AlwaysNever,\n    span: Span,\n    operator: &str,\n    can_fix: bool,\n) -> OxcDiagnostic {\n    let msg = if &AlwaysNever::Never == mode {\n        format!(\"Unexpected operator assignment ({operator}) shorthand.\")\n    } else {\n        format!(\"Assignment (=) can be replaced with operator assignment ({operator}).\")\n    };\n    let mut diagnostic = OxcDiagnostic::warn(msg).with_label(span);\n\n    if !can_fix {\n        diagnostic = diagnostic.with_note(if &AlwaysNever::Never == mode {\n            format!(\"Replace '{operator}' with a regular '=' assignment.\")\n        } else {\n            format!(\"Use '{operator}' shorthand instead of '='.\")\n        });\n    }\n\n    diagnostic\n}\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize)]\npub struct OperatorAssignment(AlwaysNever);\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/operator_assignment.rs#L15-L51","documentation":"Diagnostic from the oxlint `operator-assignment` rule in `never` mode. It flags compound assignment operators (`+=`, `-=`, `*=`, `<<=`, etc.) and wants them expanded to regular `=` assignments, e.g. `x += y` should be `x = x + y` (operator_assignment.rs:33-38). When the linter cannot auto-fix, a note explains the manual replacement.","triggerScenarios":"Configure `\"operator-assignment\": [\"error\", \"never\"]` and lint any compound assignment such as `x *= 2` or `flags |= MASK`. The `{operator}` placeholder is the compound operator found.","commonSituations":"Configs ported from teams that find compound operators harder to read in diffs; search-and-replace style code audits that match on `x = x + ...`; accidentally leaving \"never\" after copying an unrelated config block.","solutions":["Expand the shorthand: `x += y` becomes `x = x + y`.","If shorthand is preferred (the common style), configure `[\"error\", \"always\"]` — the default.","Use an inline disable comment for lines where the compound form is deliberate (e.g. bitwise flag updates).","Run `oxlint --fix` for the auto-fixable cases (simple `identifier op= expr`)."],"exampleFix":"// before\nx += y;\n\n// after\nx = x + y;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — \"always\" is the common default\n{ \"rules\": { \"operator-assignment\": [\"warn\", \"always\"] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use compound operators (`+=`) by default; \"never\" mode is rare.","If \"never\" is house style, expand shorthands as you write them or run `oxlint --fix`.","Double-check the mode when copying config from another team."],"tags":["oxlint","eslint","style","operators","assignment"],"backgroundTag":"eslint-operator-assignment","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"}