Skip to content

[class-literal-property-style] should not fix readonly to getter when assigned in ctor #2206

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

Closed
k3nsei opened this issue Jun 11, 2020 · 6 comments · Fixed by #8412
Closed
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@k3nsei
Copy link

k3nsei commented Jun 11, 2020

Repro

Playground

{
  "rules": {
    "@typescript-eslint/class-literal-property-style": ["error", "getters"],
    "@typescript-eslint/prefer-readonly": "warn"
  }
}
export class A {
  private readonly foo: string = 'bar';

  constructor(foo: string) {
    this.foo = foo;
  }
}

Expected Result
Code should be unchanged

Actual Result
Code after fix is invalid

export class A {
  private get foo() { return 'bar'; }

  constructor(foo: string) {
    this.foo = foo;
  }
}

Additional Info
None

Versions

package version
@typescript-eslint/eslint-plugin 3.2.0
@typescript-eslint/parser 3.2.0
TypeScript 3.9.5
ESLint 7.2.0
node 14.2.0
npm 6.14.5
yarn 1.22.4
@k3nsei k3nsei added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jun 11, 2020
@k3nsei
Copy link
Author

k3nsei commented Jun 11, 2020

@all-contributors please add k3nsei for bug

@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed triage Waiting for team members to take a look labels Jun 11, 2020
@ChaiWithJai
Copy link

Is anyone currently working on this? Can I take a stab at it?

@bradzacher
Copy link
Member

feel free to have a go!

@ChaiWithJai
Copy link

@JoshuaKGoldberg wanna pair on this?

@JoshuaKGoldberg
Copy link
Member

Funny looking kid dancing to "Hell Yeah!"

@jerone
Copy link
Contributor

jerone commented Sep 29, 2023

Playground.

Error:

Literals should be exposed using getters. 2:20 - 2:23

@Josh-Cena Josh-Cena changed the title [@typescript-eslint/class-literal-property-style] Fix breakes code [class-literal-property-style] readonly fields are still assignable in ctor, cannot fix to getters Dec 17, 2023
@Josh-Cena Josh-Cena changed the title [class-literal-property-style] readonly fields are still assignable in ctor, cannot fix to getters [class-literal-property-style] should not fix readonly to getter when assigned in ctor Dec 17, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 26, 2024
@bradzacher bradzacher added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
5 participants