useGetterReturn
Summary
Section titled “Summary”- Rule available since: v1.0.0
- Diagnostic Category: lint/suspicious/useGetterReturn
- This rule is recommended, which means is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
- Same as getter-return
 
- Same as 
How to configure
Section titled “How to configure”{  "linter": {    "rules": {      "suspicious": {        "useGetterReturn": "error"      }    }  }}Description
Section titled “Description”Enforce get methods to always return a value.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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];    }}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.