Skip to content

fix(biome-js-analyze): add tests for useReadonlyClassProperties#7315

Merged
ematipico merged 3 commits intobiomejs:mainfrom
vladimir-ivanov:feat-issue-7310-adding-tests-use-readonly-class-properties
Aug 28, 2025
Merged

fix(biome-js-analyze): add tests for useReadonlyClassProperties#7315
ematipico merged 3 commits intobiomejs:mainfrom
vladimir-ivanov:feat-issue-7310-adding-tests-use-readonly-class-properties

Conversation

@vladimir-ivanov
Copy link
Contributor

Summary

Adds tests to confirm already fixed issues in pull request: #7015

Closes #7310

@changeset-bot
Copy link

changeset-bot bot commented Aug 24, 2025

🦋 Changeset detected

Latest commit: ecfab31

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

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

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 24, 2025

Walkthrough

Adds two new test classes to valid.ts under the useReadonlyClassProperties rule tests: one validating a nested UpdateExpression case (obj.prop = this.thing++;) and another validating an assignment inside a nested callback. Also adds a patch changeset documenting the fix for nested assignments related to issue #7310. No public APIs or exports are modified.

Assessment against linked issues

Objective Addressed Explanation
Recognise UpdateExpression on class field inside assignment RHS (postfix case) [#7310]
Cover prefix and decrement variants (++x, --x) and private field access forms [#7310] No evidence of tests or code covering prefix/-- variants or true private fields (\#field).
Avoid false positives for pure reads [#7310] No test changes demonstrating pure-read scenarios retained as diagnostics.
Add tests asserting no diagnostic for obj.prop = this.x++; [#7310]

Assessment against linked issues: Out-of-scope changes

(No out-of-scope functional changes identified.)

Possibly related PRs

Suggested reviewers

  • ematipico

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1e60618 and ecfab31.

📒 Files selected for processing (1)
  • .changeset/use_readonly_class_properties_nested_assignment_fix.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/use_readonly_class_properties_nested_assignment_fix.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Aug 24, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
crates/biome_js_analyze/tests/quick_test.rs (2)

28-29: Quick test is enabled but has no assertion — either assert or re-ignore.

As written, the test always passes and only prints diagnostics. Either make it meaningful by asserting no diagnostics, or keep it opt-in via #[ignore] to avoid CI noise.

Apply one of the following:

Option A — make it assertive:

-// #[ignore]
+// #[ignore]

@@
-    // assert_eq!(error_ranges.as_slice(), &[]);
+    assert_eq!(error_ranges.as_slice(), &[]);

Option B — keep it opt-in:

-// #[ignore]
+#[ignore]

32-43: Optionally broaden coverage to private fields and pre-increment.

If you want this ad-hoc to mirror the spec coverage, consider adding a variant with a class field and pre-increment:

 class Test {
-  private thing: any;
+  private thing: any;
+  #field: number = 0;
@@
       callback: () => {
         this.thing = x;
       },
     });
   }
 }
+
+class Test2 {
+  #n: number = 0;
+  bump(): void {
+    const t = { x: 0 };
+    t.x = ++this.#n;
+  }
+}
crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.ts (3)

667-675: Add mirrored cases for private fields and pre/compound assignments.

To fully cover the patterns mentioned in the issue, add:

  • A mirror using a class private field (#field): temp.x = this.#thing++;
  • A pre-increment variant: temp.x = ++this.thing;
  • A compound-assignment-as-expression: temp.x = (this.thing += 1);

Example additions (outside this hunk):

class TestIncrementInAssignmentPrivateField {
	#thing: number = 0;
	incrementThing(): void {
		const temp = { x: 0 };
		temp.x = this.#thing++;
	}
}

class TestPreIncrementInAssignment {
	private thing: number = 0;
	incrementThing(): void {
		const temp = { x: 0 };
		temp.x = ++this.thing;
	}
}

class TestCompoundAssignmentInAssignment {
	private thing: number = 0;
	incrementThing(): void {
		const temp = { x: 0 };
		temp.x = (this.thing += 1);
	}
}

677-687: Typo: rename TesAssignmentInNestedCallback → TestAssignmentInNestedCallback.

Keeps naming consistent with the rest of the file.

-class TesAssignmentInNestedCallback {
+class TestAssignmentInNestedCallback {

677-687: Optional: declare ui and x to make the snippet self-contained.

Not required for this rule, but avoids surprises if other checks ever run over this file.

Add near the top (outside this hunk):

declare const ui: { showText(msg: string, opts: { callback: () => void }): void };
declare const x: unknown;
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7638e84 and 1e60618.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.ts.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (2)
  • crates/biome_js_analyze/tests/quick_test.rs (2 hunks)
  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{rs,toml}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Format Rust and TOML files before committing (use just f/just format).

Files:

  • crates/biome_js_analyze/tests/quick_test.rs
crates/biome_*_{syntax,parser,formatter,analyze,factory,semantic}/**

📄 CodeRabbit inference engine (CLAUDE.md)

Maintain the per-language crate structure: biome_{lang}_{syntax,parser,formatter,analyze,factory,semantic}

Files:

  • crates/biome_js_analyze/tests/quick_test.rs
  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.ts
crates/biome_*/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place core crates under /crates/biome_*/

Files:

  • crates/biome_js_analyze/tests/quick_test.rs
  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.ts
**/tests/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place test files under a tests/ directory in each crate

Files:

  • crates/biome_js_analyze/tests/quick_test.rs
  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.ts
🧠 Learnings (4)
📚 Learning: 2025-08-17T08:56:30.831Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-17T08:56:30.831Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/tests/quick_test.rs : Use `biome_js_analyze/tests/quick_test.rs` for quick, ad-hoc testing; un-ignore the test and adjust the rule filter as needed

Applied to files:

  • crates/biome_js_analyze/tests/quick_test.rs
📚 Learning: 2025-08-17T08:56:30.831Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-17T08:56:30.831Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/lib/src/lint/nursery/*.rs : For new JavaScript lint rules generated by `just new-js-lintrule`, implement the rule in the generated file under `biome_js_analyze/lib/src/lint/nursery/`

Applied to files:

  • crates/biome_js_analyze/tests/quick_test.rs
📚 Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/src/**/*.rs : Use TypeData::Unknown for unimplemented inference and TypeData::UnknownKeyword for the explicit TypeScript unknown keyword; treat them semantically the same but keep them distinct for measurement

Applied to files:

  • crates/biome_js_analyze/tests/quick_test.rs
📚 Learning: 2025-08-17T08:56:30.831Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-17T08:56:30.831Z
Learning: Applies to crates/biome_analyze/crates/**/tests/specs/**/{invalid*,valid*}.{js,jsx,ts,tsx,css,graphql,jsonc} : Place snapshot test cases under `tests/specs/<group>/<ruleName>/` using files prefixed with `invalid` and `valid`

Applied to files:

  • crates/biome_js_analyze/tests/quick_test.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/tests/quick_test.rs (3)
crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.ts (6)
  • test (323-325)
  • test (333-335)
  • test (409-411)
  • test (419-421)
  • test (431-433)
  • test (443-445)
crates/biome_js_analyze/src/suppressions.tests.rs (1)
  • quick_test (12-60)
crates/biome_service/src/file_handlers/mod.rs (1)
  • rule_filter (1135-1135)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: Documentation
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
🔇 Additional comments (3)
crates/biome_js_analyze/tests/quick_test.rs (2)

32-43: Good regression snippet for nested-callback assignment.

This neatly exercises the “assignment inside an arrow callback” case for the rule. Nice and focused.


60-60: Rule filter points to the right rule.

Targeting style/useReadonlyClassProperties is correct for this PR’s objective.

crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.ts (1)

667-675: Solid case: post-increment used as RHS of a property assignment.

This directly addresses the regression in #7310 and should prevent the readonly false positive.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 24, 2025

CodSpeed Performance Report

Merging #7315 will not alter performance

Comparing vladimir-ivanov:feat-issue-7310-adding-tests-use-readonly-class-properties (1e60618) with main (7638e84)

Summary

✅ 133 untouched benchmarks

@ematipico
Copy link
Member

Closes #7310

Did we add a changeset for that?

@vladimir-ivanov
Copy link
Contributor Author

Closes #7310

Did we add a changeset for that?

no, because it only adds test and no changes in code? my understanding is we should not do one in this instance. Please confirm

@ematipico
Copy link
Member

ematipico commented Aug 24, 2025

From the description, I understood that the issue was fixed in #7015

Here you added tests to confirm the fix. This means we fixed the issue, but I think we didn't add a changeset for the fix.

@vladimir-ivanov
Copy link
Contributor Author

From the description, I understood that the issue was fixed in #7015

Here you added tests to confirm the fix. This means we fixed the issue, but I think we didn't add a changeset for the fix.

ok, yes that makes perfect sense now. thanks for the explanation. let me add a changeset.

Copy link
Member

@chansuke chansuke left a comment

Choose a reason for hiding this comment

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

lgtm

@ematipico ematipico merged commit 4a2bd2f into biomejs:main Aug 28, 2025
13 checks passed
@github-actions github-actions bot mentioned this pull request Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 lint/style/useReadonlyClassProperties doesn't recognize obj.prop = this.x++;

3 participants