Skip to content

Rule proposal: Prefer readonly member variables instead of getters that return literal values, or vice versa #1556

@c32hedge

Description

@c32hedge

I'm finding a common pattern in our code:

  export class PageObject {
    get saveButton() {
      return '[data-testid="saveButton"]';
    }
  }

I would like to enforce using simple readonly members instead of getter functions:

  export class PageObject {
    readonly saveButton = '[data-testid="saveButton"]';
  }

This could also be applied to getter functions that return other literals, such as integers.

Some people prefer the reverse, so the rule should be bidirectional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy