Skip to content

[prefer-signals] Convert suggestion fix to full autofix for readonly requirement #2170

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
2 tasks done
Frotty opened this issue Dec 9, 2024 · 7 comments · Fixed by #2175
Closed
2 tasks done

[prefer-signals] Convert suggestion fix to full autofix for readonly requirement #2170

Frotty opened this issue Dec 9, 2024 · 7 comments · Fixed by #2175
Labels
package: eslint-plugin Angular-specific TypeScript rules PRs Welcome If a high-quality PR is created for this it will be accepted

Comments

@Frotty
Copy link

Frotty commented Dec 9, 2024

Description and reproduction of the issue

When linting a project that uses the new prefer-signals with the --fix option provided, the plugin reports that signals should be readonly.
It seems that it should be a trivial auto-fix, to add readonly to the signal definition. It would be nice if this were added.

REPRO: https://stackblitz.com/edit/angular-eslint-repros-2qja2h9n?file=package.json
Just run ng lint --fix.

❯ ng lint --fix

Linting "demo"...

/home/projects/angular-eslint-repros/src/main.ts
  14:3  error  Properties declared using signals should be marked as `readonly` since they should not be reassigned  @angular-eslint/prefer-signals

✖ 1 problem (1 error, 0 warnings)

Lint errors found in the listed files.

Versions

package version
@angular-eslint/eslint-plugin 19.0.1
Angular CLI: 19.0.0
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64

Angular: 19.0.0
... animations, build, cli, common, compiler, compiler-cli, core
... forms, platform-browser, router

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1900.0
@angular-devkit/core         19.0.0
@angular-devkit/schematics   19.0.0
@schematics/angular          19.0.0
rxjs                         7.8.1
typescript                   5.6.3
zone.js                      0.15.0
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest supported version of the packages and checked my ng version output per the instructions given here.
@Frotty Frotty added package: eslint-plugin Angular-specific TypeScript rules triage This issue needs to be looked at and categorized by a maintainer labels Dec 9, 2024
Copy link

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@JamesHenry
Copy link
Member

Would you like to submit a PR?

@JamesHenry JamesHenry added the PRs Welcome If a high-quality PR is created for this it will be accepted label Dec 10, 2024
@JamesHenry
Copy link
Member

Wait this was already added as a suggestion, rather than an auto fix. So it is already available to apply via your IDE tooling

@JamesHenry
Copy link
Member

@reduckted the author, can maybe speak more to why suggestion vs autofix here

@JamesHenry JamesHenry removed the PRs Welcome If a high-quality PR is created for this it will be accepted label Dec 10, 2024
@reduckted
Copy link
Contributor

🤔 That is a very good question. I think I copied the prefer-output-readonly rule which also uses a suggestion.

@JamesHenry
Copy link
Member

Cool yeah it's definitely a very blurry line... But given the rule is opt in, and you can even control this "sub-violation", maybe it makes sense to just promote it to a full fix.

I'll mark it as PRs Welcome, please comment if either of you wants to take it

@JamesHenry JamesHenry added PRs Welcome If a high-quality PR is created for this it will be accepted and removed triage This issue needs to be looked at and categorized by a maintainer labels Dec 10, 2024
@JamesHenry JamesHenry changed the title [prefer-signals] Provide autofix for readonly requirement [prefer-signals] Convert suggestion fix to full autofix for readonly requirement Dec 10, 2024
@reduckted
Copy link
Contributor

I'll take it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: eslint-plugin Angular-specific TypeScript rules PRs Welcome If a high-quality PR is created for this it will be accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants