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.
Examples
Section titled “Examples”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; }}const object = { set value(val) { this._value = val; },};class Example { set name(value) { this._name = value; }}const object = { set value(val) { if (!val) { return; } this._value = val; },};Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noSetterReturn - Deno:
no-setter-return - ESLint:
no-setter-return - Oxlint:
eslint/no-setter-return
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.