{"record":{"id":"b4ba39238eaf8001","repo":"oxc-project/oxc","slug":"setter-cannot-return-a-value","errorCode":null,"errorMessage":"Setter cannot return a value","messagePattern":"Setter cannot return a value","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_setter_return.rs","lineNumber":9,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_setter_return_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Setter cannot return a value\")\n        .with_help(\"Remove the return statement or ensure it does not return a value.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoSetterReturn;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Setters cannot return values.\n    ///\n    /// This rule can be disabled for TypeScript code, as the TypeScript compiler\n    /// enforces this check.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// While returning a value from a setter does not produce an error, the returned value is","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_setter_return.rs#L1-L27","documentation":"oxlint's port of ESLint `no-setter-return`. Per the ECMAScript spec the value returned from a setter's `return` statement is ignored, so `return someValue;` inside a `set` accessor is dead data that misleads readers. The rule flags any `return <expr>;` inside a setter.","triggerScenarios":"`set name(v) { this._name = v; return v; }` — also `return this._name = v;` (which trips both this rule and no-return-assign). Bare `return;` inside a setter is allowed.","commonSituations":"Copy-pasting a getter body into a setter; developers expecting chainability that the language does not provide.","solutions":["Change to a bare `return;` or remove the return statement entirely.","If the value must flow onward, restructure the API as a normal method (`setName(v)`)."],"exampleFix":"// before\nset name(v) {\n  this._name = v;\n  return v;\n}\n\n// after\nset name(v) {\n  this._name = v;\n}","handlingStrategy":"validation","validationCode":"// Rough guard: `return <expr>;` inside a set accessor\nfunction setterReturnValue(src) {\n  const setters = [...src.matchAll(/\\bset\\s+\\w+\\s*\\([^)]*\\)\\s*\\{([\\s\\S]*?)\\}/g)];\n  return setters.some(m => /return\\s+[^;\\s]/.test(m[1]));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Setters should only mutate; make them `return;`-free entirely.","If callers need the value back, model the operation as a plain method instead of an accessor.","When copying a getter into a setter, delete its return statement as part of the edit."],"tags":["lint","eslint","no-setter-return","accessors","possible-bug"],"backgroundTag":"setter-return-value","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"}