Skip to content

feat(biome_js_analyze): adds new lint rule useReadonlyClassProperties#6297

Merged
vladimir-ivanov merged 6 commits intobiomejs:mainfrom
vladimir-ivanov:feat/useReadonlyClassProperties
Jun 21, 2025
Merged

feat(biome_js_analyze): adds new lint rule useReadonlyClassProperties#6297
vladimir-ivanov merged 6 commits intobiomejs:mainfrom
vladimir-ivanov:feat/useReadonlyClassProperties

Conversation

@vladimir-ivanov
Copy link
Copy Markdown
Contributor

@vladimir-ivanov vladimir-ivanov commented Jun 12, 2025

Summary

Adds a new lint useReadonlyClassProperties rule.
This rule implements ESLint's prefer-readonly rule.

Example:

class Example {
    // All properties below can be marked as readonly
    public constantValue = 42;
    protected initializedInConstructor: string;
    private privateField = true;

    constructor(initializedInConstructor: string) {
        this.initializedInConstructor = initializedInConstructor;
    }
}
  • collect all mutated class properties (their names in Vec)
  • collect all class member properties defined normally (not in constructor) -> e.g. class Test {public prop1}
  • collect all constructor (not marked as readonly) parameters which typescipt turns into class properties e.g. constructor(public prop1) {}
  • merges the class members and class properties (and excludes dups if found from constructor params)
  • checks the merged collection against all mutated class properties and extracts their Text and Range to be used in diagnostics and action

closes #4356

@github-actions github-actions Bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Jun 12, 2025
@vladimir-ivanov vladimir-ivanov force-pushed the feat/useReadonlyClassProperties branch 2 times, most recently from e85d341 to 34afc91 Compare June 12, 2025 17:43
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 12, 2025

CodSpeed Performance Report

Merging #6297 will not alter performance

Comparing vladimir-ivanov:feat/useReadonlyClassProperties (aaf0bfd) with main (00e97ad)

Summary

✅ 115 untouched benchmarks

@vladimir-ivanov vladimir-ivanov force-pushed the feat/useReadonlyClassProperties branch 2 times, most recently from 2cb99b6 to 420d2b3 Compare June 13, 2025 05:32
@vladimir-ivanov
Copy link
Copy Markdown
Contributor Author

any ideas on what to do about performance please? does it need addressing to start with?

@vladimir-ivanov vladimir-ivanov force-pushed the feat/useReadonlyClassProperties branch 3 times, most recently from 44d7dc0 to 7b0dce7 Compare June 13, 2025 05:53
@ematipico
Copy link
Copy Markdown
Member

We recently changed the way we do benchmarks (sharding), so the benchmarks we ignored before need to be ignored again, unfortunately. That's one of them.

TLDR: no need to address the benchmark

@vladimir-ivanov vladimir-ivanov force-pushed the feat/useReadonlyClassProperties branch from 7b0dce7 to c40ead4 Compare June 13, 2025 06:00
Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @vladimir-ivanov, I left some suggestions. There's a bit of rework to do, so please take your time to address the suggestions. Mainly, here's the important things to address:

  • Documentation: let's follow the same format we use everywhere. Use other rules to check how we do it
  • Doc comments: please document all internal functions, explaining what they do. Since this is a shared code base, we want to make sure to document as much know-how that we can, so the next developer won't have hard time understanding things
  • Tests: let's borrow the test suite from the eslint rule
  • Strong typed coding: let's avoid returning SyntaxNodes, and let's try to use a stricter approach, it will make the code more readable, safer and easier to use.

Comment thread .changeset/use_readonly_class_properties_definition.md Outdated
Comment thread .changeset/use_readonly_class_properties_definition.md Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
@vladimir-ivanov vladimir-ivanov force-pushed the feat/useReadonlyClassProperties branch 8 times, most recently from c628c77 to d2440e8 Compare June 13, 2025 14:55
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
@vladimir-ivanov vladimir-ivanov force-pushed the feat/useReadonlyClassProperties branch 3 times, most recently from f7c4d03 to f4b89e4 Compare June 13, 2025 16:19
Comment thread crates/biome_js_analyze/tests/specs/nursery/useReadonlyClassProperties/valid.ts Outdated
@vladimir-ivanov vladimir-ivanov force-pushed the feat/useReadonlyClassProperties branch from b0b1c8c to e0e1925 Compare June 18, 2025 06:43
@github-actions github-actions Bot added A-Formatter Area: formatter L-CSS Language: CSS and super languages labels Jun 18, 2025
@vladimir-ivanov
Copy link
Copy Markdown
Contributor Author

need to remove the unwrap() usages in fact, please bare with me a couple of hours

@vladimir-ivanov vladimir-ivanov force-pushed the feat/useReadonlyClassProperties branch from e0e1925 to 8c9c1ef Compare June 18, 2025 08:15
@ematipico
Copy link
Copy Markdown
Member

I think the benchmarks message is the result of a bad commit, or merge resolution. In fact, there are now 333 files changed.

@vladimir-ivanov vladimir-ivanov force-pushed the feat/useReadonlyClassProperties branch 2 times, most recently from fd4435f to f590ac2 Compare June 18, 2025 08:39
@github-actions github-actions Bot removed A-Project Area: project A-Linter Area: linter A-Formatter Area: formatter labels Jun 18, 2025
@vladimir-ivanov
Copy link
Copy Markdown
Contributor Author

@ematipico @Conaclos please resume the review, all covered now, no more unwrap() etc. many thanks

@vladimir-ivanov
Copy link
Copy Markdown
Contributor Author

Thank you @vladimir-ivanov, I left some suggestions. There's a bit of rework to do, so please take your time to address the suggestions. Mainly, here's the important things to address:

  • Documentation: let's follow the same format we use everywhere. Use other rules to check how we do it
  • Doc comments: please document all internal functions, explaining what they do. Since this is a shared code base, we want to make sure to document as much know-how that we can, so the next developer won't have hard time understanding things
  • Tests: let's borrow the test suite from the eslint rule
  • Strong typed coding: let's avoid returning SyntaxNodes, and let's try to use a stricter approach, it will make the code more readable, safer and easier to use.

hope everything is covered now here, but please shout if I missed anything

Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @vladimir-ivanov. There's a comment that hasn't been addressed, I tagged you in it.

The implementation of the rule has become big. In such cases, we ask the contributors to use the PR description to explain the implementation of the code, which helps reviewers to assimilate an overview of the algorithm and how to review the PR.

There's a regression in our benchmarks, so we should take a look at it if possible.

Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
Comment thread crates/biome_js_analyze/src/lint/nursery/use_readonly_class_properties.rs Outdated
@vladimir-ivanov
Copy link
Copy Markdown
Contributor Author

Thank you @vladimir-ivanov. There's a comment that hasn't been addressed, I tagged you in it.

The implementation of the rule has become big. In such cases, we ask the contributors to use the PR description to explain the implementation of the code, which helps reviewers to assimilate an overview of the algorithm and how to review the PR.

There's a regression in our benchmarks, so we should take a look at it if possible.

Thank you @vladimir-ivanov. There's a comment that hasn't been addressed, I tagged you in it.

The implementation of the rule has become big. In such cases, we ask the contributors to use the PR description to explain the implementation of the code, which helps reviewers to assimilate an overview of the algorithm and how to review the PR.

There's a regression in our benchmarks, so we should take a look at it if possible.

please check the description at the top of this pr, and also added more details per fn description. Hope it is a bit more intuitive now? if not, please let me know, will add more :_0

@vladimir-ivanov
Copy link
Copy Markdown
Contributor Author

@ematipico hope we are close to where we should be, please re check and answer my questions?

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 20, 2025

🦋 Changeset detected

Latest commit: aaf0bfd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@biomejs/biome Minor
@biomejs/cli-win32-x64 Minor
@biomejs/cli-win32-arm64 Minor
@biomejs/cli-darwin-x64 Minor
@biomejs/cli-darwin-arm64 Minor
@biomejs/cli-linux-x64 Minor
@biomejs/cli-linux-arm64 Minor
@biomejs/cli-linux-x64-musl Minor
@biomejs/cli-linux-arm64-musl Minor
@biomejs/wasm-web Minor
@biomejs/wasm-bundler Minor
@biomejs/wasm-nodejs Minor
@biomejs/backend-jsonrpc Patch
@biomejs/js-api Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @vladimir-ivanov ! I know it was a lot of work, but I hope you had fun and learned a bit more about how Biome works. (CI is failing)

@vladimir-ivanov
Copy link
Copy Markdown
Contributor Author

Thank you @vladimir-ivanov ! I know it was a lot of work, but I hope you had fun and learned a bit more about how Biome works. (CI is failing)

yep, this was my graduation pr :-). Now I feel a bit more confident with what I am doing and can actually think about making things better too.

many thanks for your help.

And please merge once the build goes green? had a small issue with Empasis tag

@vladimir-ivanov
Copy link
Copy Markdown
Contributor Author

can we merge this pr please?

@github-actions github-actions Bot mentioned this pull request Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages L-JSON Language: JSON and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Implement useReadonlyClassProperties - typescript-eslint/prefer-readonly

3 participants