Skip to content

setterReturns

Reports return statements with values inside setters.

✅ This rule is included in the ts javascript 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
const object: {
value: any;
}
object
= {
set
value: any
value
(
val: any
val
) {
return
val: any
val
;
},
};
class
class Example
Example
{
set
Example.name: any
name
(
value: any
value
) {
return
value: any
value
;
}
}
class
class Example
Example
{
set
Example.value: any
value
(
val: any
val
) {
if (
val: any
val
> 0) {
return
val: any
val
;
}
this.
any
_value
=
val: any
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 ❤️‍🔥 around the world by the Flint team and contributors.