Skip to main content

js/noGetterReturn

enforce return statements in getters

ESLint Equivalent: getter-return

Examples

Invalid

class p {
	get name() {
		console.log('hello');
	}
}

 file.ts:2:12 lint/js/noGetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Return a value at the end of a getter method instead of empty block.

    1class p {
  > 2  get name() {
                  ^
  > 3    console.log('hello');
  > 4  }
     ^^^
    5}

  Getters that do not return values are either typos or should not be
    getters.


let p = {
	get name() {
		console.log('hello');
	},
};

 file.ts:2:12 lint/js/noGetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Return a value at the end of a getter method instead of empty block.

    1let p = {
  > 2  get name() {
                  ^
  > 3    console.log('hello');
  > 4  },
     ^^^
    5};

  Getters that do not return values are either typos or should not be
    getters.

Valid

let p = {};
Object.defineProperty(p, {
	get: function () {
		console.log('hello');
	},
});