Skip to content

setterReturns

Reports return statements with values inside setters.

✅ This rule is included in the ts untyped presets.

The set syntax binds an object property to a function that will be called when there is an attempt to set that property. Setters are expected to have side effects only and not produce a return value. Any value returned from a setter is ignored by the JavaScript engine.

This rule reports when a setter contains a return statement with a value.

const object = {
set value(val) {
return val;
},
};
class Example {
set name(value) {
return value;
}
}
class Example {
set value(val) {
if (val > 0) {
return val;
}
this._value = val;
}
}

This rule is not configurable.

If you are using an unusual non-standard tool that modifiers your setters at build time into standard functions, this rule may not be for you.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.