useGetterReturn
Diagnostic Category: lint/suspicious/useGetterReturn
Since: v1.0.0
Sources:
- Same as:
getter-return
Enforce get
methods to always return a value.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:2:5 lint/suspicious/useGetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This getter should return a value.
1 │ class Person {
> 2 │ get firstName() {}
│ ^^^^^^^^^^^^^^^^^^
3 │ }
4 │
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 │ }
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 │