Pular para o conteúdo

useGetterReturn

Este conteúdo não está disponível em sua língua ainda.

Diagnostic Category: lint/suspicious/useGetterReturn

Since: v1.0.0

Sources:

Enforce get methods to always return a value.

class Person {
get firstName() {}
}
code-block.js:2:5 lint/suspicious/useGetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This getter should return a value.

1 │ class Person {
> 2 │ get firstName() {}
^^^^^^^^^^^^^^^^^^
3 │ }
4 │

const obj = {
get firstName() {
return;
}
}
code-block.js:3:9 lint/suspicious/useGetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This return should return a value because it is located in a getter.

1 │ const obj = {
2 │ get firstName() {
> 3 │ return;
^^^^^^^
4 │ }
5 │ }

class Option {
get value() {
if (this.hasValue) {
log();
} else {
return null;
}
}
}
code-block.js:2:5 lint/suspicious/useGetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This getter should return a value.

1 │ class Option {
> 2 │ get value() {
^^^^^^^^^^^^^
> 3 │ if (this.hasValue) {
> 4 │ log();
> 5 │ } else {
> 6 │ return null;
> 7 │ }
> 8 │ }
^
9 │ }
10 │

class Person {
get firstName() {
return this.fullname.split(" ")[0];
}
}
const obj = {
get firstName() {
return this.fullname.split(" ")[0];
}
}