src/content/docs/linter/rules/no-setter-return.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/correctness/noSetterReturn`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`no-setter-return`](https://eslint.org/docs/latest/rules/no-setter-return){
"linter": {
"rules": {
"correctness": {
"noSetterReturn": "error"
}
}
}
}
Disallow returning a value from a setter
While returning a value from a setter does not produce an error, the returned value is being ignored. Therefore, returning a value from a setter is either unnecessary or a possible error.
Only returning without a value is allowed, as it’s a control flow statement.
class A {
set foo(x) {
return x;
}
}
const b = {
set foo(x) {
return x;
},
};
const c = {
set foo(x) {
if (x) {
return x;
}
},
};
// early-return
class A {
set foo(x) {
if (x) {
return;
}
}
}
// not a setter
class B {
set(x) {
return x;
}
}