{"record":{"id":"cb8e92314dc45acc","repo":"oxc-project/oxc","slug":"unexpected-side-effect-in-key-computed-propert","errorCode":null,"errorMessage":"Unexpected side effect in \"{key}\" computed property.","messagePattern":"Unexpected side effect in \"(.+?)\" computed property\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/vue/no_side_effects_in_computed_properties.rs","lineNumber":20,"sourceCode":"    AstKind,\n    ast::{CallExpression, Expression, IdentifierReference, UnaryOperator},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    frameworks::FrameworkOptions,\n    rule::Rule,\n    utils::{\n        ComputedContext, find_computed_context, is_this_object, is_vue_component_options_object,\n    },\n};\n\nfn unexpected_side_effect_in_property(span: Span, key: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Unexpected side effect in \\\"{key}\\\" computed property.\"))\n        .with_label(span)\n}\n\nfn unexpected_side_effect_in_function(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected side effect in computed function.\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoSideEffectsInComputedProperties;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow side effects in computed properties.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// It is considered a very bad practice to introduce side effects inside computed properties.","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vue/no_side_effects_in_computed_properties.rs#L2-L38","documentation":"The named-key diagnostic of vue/no-side-effects-in-computed-properties: 'Unexpected side effect in \"{key}\" computed property.' Computed properties must be pure — Vue caches them and re-evaluates only when reactive deps change, so assignments or other mutations inside a computed cause extra renders, 'computed was written to' warnings, or infinite update loops. The rule locates computed properties via ComputedContext/find_computed_context in objects recognized as component options and inspects their bodies (including `this.` object usage via is_this_object) for side effects.","triggerScenarios":"An object-syntax computed like `computed: { fullName: { get() { ...; this.firstName = x; return ... } } }` — any assignment, `this.someProp = ...`, or state-mutating call inside the getter, reported with the property's key name.","commonSituations":"Getters that 'normalize and store' the result on the instance; writing back a formatted value inside the computed that reads it; cache-invalidation hacks inside getters; code moved out of methods into computed during refactors.","solutions":["Move the mutation out of the computed — do writes in a method, watcher (`watch`), or event handler instead.","If you need get/set behavior, use a writable computed with an explicit `set` function and keep the `get` pure.","Derive intermediate values with additional pure computeds rather than storing them in `data`.","Re-run oxlint to confirm."],"exampleFix":"// before\ncomputed: {\n  normalized: {\n    get() {\n      this.cache = this.raw.trim(); // side effect\n      return this.cache;\n    }\n  }\n}\n\n// after\ncomputed: {\n  normalized() {\n    return this.raw.trim();\n  }\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep computed getters pure: read reactive state, return a value, nothing else.","Use a writable computed's `set` (or a method/watcher) for writes.","Enable this rule in CI to catch 'computed wrote back' patterns during review."],"tags":["vue","computed","lint","side-effects","options-api"],"backgroundTag":"side-effects-in-computed","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"}