Skip to main content

js/noSetterReturn

disallow returning values from setters

ESLint Equivalent: no-setter-return

Examples

Invalid

class p {
	set name(value) {
		if (!value) {
			return 'wrong';
		}
	}
}

 file.ts:4:3 lint/js/noSetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not return a value at the end of a setter method.

    2  set name(value) {
    3    if (!value) {
  > 4      return 'wrong';
           ^^^^^^^^^^^^^^^
    5    }
    6  }

  Setters that return values are either typos or should not be setters.


class p {
	static set name(value) {
		if (!value) {
			return 'wrong';
		}
	}
}

 file.ts:4:3 lint/js/noSetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not return a value at the end of a setter method.

    2  static set name(value) {
    3    if (!value) {
  > 4      return 'wrong';
           ^^^^^^^^^^^^^^^
    5    }
    6  }

  Setters that return values are either typos or should not be setters.


let p = {
	set name(value) {
		if (!value) {
			return 'wrong';
		}
	}
};

 file.ts:4:3 lint/js/noSetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not return a value at the end of a setter method.

    2  set name(value) {
    3    if (!value) {
  > 4      return 'wrong';
           ^^^^^^^^^^^^^^^
    5    }
    6  }

  Setters that return values are either typos or should not be setters.

Valid

class p {
	set name(value) {
		if (!value) {
			return;
		}
	}
}