Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
c32hedge opened this issue Feb 1, 2020 · 1 comment · Fixed by #1582
Labels
enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@c32hedge
Copy link

c32hedge commented Feb 1, 2020

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.

@c32hedge c32hedge added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 1, 2020
@bradzacher bradzacher added enhancement: new plugin rule New rule request for eslint-plugin and removed triage Waiting for maintainers to take a look labels Feb 1, 2020
@sindresorhus
Copy link

I would prefer the inverse, as I make reusable packages that will be consumed by JS users too, and I want to ensure it can only be read from, not assigned.

@c32hedge c32hedge changed the title Rule proposal: Prefer readonly member variables instead of getters that return literal values Rule proposal: Prefer readonly member variables instead of getters that return literal values, or vice versa Feb 3, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants