oxc-project/oxc · warning · OxcDiagnostic
Setter cannot return a value
Error message
Setter cannot return a value
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_setter_return.rs:9
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};
fn no_setter_return_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Setter cannot return a value")
.with_help("Remove the return statement or ensure it does not return a value.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoSetterReturn;
declare_oxc_lint!(
/// ### What it does
///
/// Setters cannot return values.
///
/// This rule can be disabled for TypeScript code, as the TypeScript compiler
/// enforces this check.
///
/// ### Why is this bad?
///
/// While returning a value from a setter does not produce an error, the returned value isView on GitHub (pinned to e1e7af627c)
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)`).
Example fix
// before
set name(v) {
this._name = v;
return v;
}
// after
set name(v) {
this._name = v;
} Defensive patterns
Strategy: validation
Validate before calling
// Rough guard: `return <expr>;` inside a set accessor
function setterReturnValue(src) {
const setters = [...src.matchAll(/\bset\s+\w+\s*\([^)]*\)\s*\{([\s\S]*?)\}/g)];
return setters.some(m => /return\s+[^;\s]/.test(m[1]));
} Prevention
- 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.
When it happens
Trigger: `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.
Common situations: Copy-pasting a getter body into a setter; developers expecting chainability that the language does not provide.
Related errors
- this expression is assigned to itself
- Both sides of this comparison are exactly the same
- Empty array binding pattern
- Empty object binding pattern
- Accessor pair {getter_key} and {setter_key} should be groupe
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/b4ba39238eaf8001.
Report an issue: GitHub.