Setter functions should not return values

  • SETTER_RETURN_VALUE
  • Code Quality
  • Low
  • No tags

This rule applies when a setter function returns a value.

Setter functions always return the passed argument and the return values in their body are ignored.

Noncompliant Code Example

View with compliant examples side by side
let language = {
    set current(name) {
        return this.log.push(name); // SETTER_RETURN_VALUE alarm because this return value will be ignored.
    },
    log: []
}
let logCount = language.current = 'foo'; // logCount gets 'foo' because setter returns the passed argument.

Compliant Code Example

View with noncompliant examples side by side
let language = {
    set current(name) {
        this.log.push(name);
    },
    log: []
}
language.current = 'foo';
let logCount = language.log.length;

Version

This rule was introduced in DeepScan 1.11.0-beta.

See