+
Skip to content

Conversation

unvalley
Copy link
Member

@unvalley unvalley commented Aug 23, 2025

Summary

Closes #7301
useReadonlyClassProperties should skip JavaScript files, because of readonly modifier is TypeScript only.

Test Plan

Added a snapshot

Docs

The useReadonlyClassProperties rule was attempting to add TypeScript-only
`readonly` modifiers to JavaScript files, which would result in syntax errors.
This change adds a check to ensure the rule only runs on TypeScript files,
consistent with other TypeScript-only rules in the codebase.
Copy link
Contributor

coderabbitai bot commented Aug 23, 2025

Walkthrough

Adds an early guard in UseReadonlyClassProperties::run to skip non-TypeScript sources by checking JsFileSource.language(). Imports JsFileSource. Adds a JavaScript test (crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.js) asserting no diagnostics for JS class fields. Adds a changeset (.changeset/grumpy-monkeys-tap.md) bumping @biomejs/biome and documenting the bug fix. No public APIs changed.

Assessment against linked issues

Objective Addressed Explanation
Rule should not apply to JavaScript files; only run on TypeScript (#7301)

Suggested reviewers

  • siketyan

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 9f1c84b and 72a82b7.

📒 Files selected for processing (1)
  • crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs
⏰ 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). (25)
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 23, 2025
Copy link

changeset-bot bot commented Aug 23, 2025

🦋 Changeset detected

Latest commit: 72a82b7

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

@unvalley unvalley marked this pull request as ready for review August 23, 2025 09:28
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: 2

🧹 Nitpick comments (3)
.changeset/grumpy-monkeys-tap.md (1)

1-5: Add a tiny example to the changeset for clarity.

Guidelines recommend including a representative snippet. A minimal JS example helps users immediately see the effect.

Proposed addition:

 ---
 "@biomejs/biome": patch
 ---
 
 Fixed [#7301](https://github.com/biomejs/biome/issues/7301): [`useReadonlyClassProperties`](https://biomejs.dev/linter/rules/use-readonly-class-properties/) now correctly skips JavaScript files.
+#### Example.
+```js
+// JavaScript — no diagnostics from this rule.
+class C {
+  x = 1;
+  #y = 2;
+}
+```
crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs (1)

275-281: Wording: “readonly decorator” → “readonly modifier”.

In TS this is a modifier, not a decorator. Minor, but user-facing.

-            markup! { "Add "<Emphasis>"readonly"</Emphasis>" decorator." }.to_owned(),
+            markup! { "Add "<Emphasis>"readonly"</Emphasis>" modifier." }.to_owned(),
crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.js (1)

1-7: Good JS coverage; consider a TS counterpart to prevent regressions.

Add a small invalid.ts or valid.ts to ensure the rule still runs on TS/TSX and produces/omits diagnostics as expected.

Example additions (as separate files):

// invalid.ts,expect_diagnostic
class C {
  private onlyInCtor = 1;
  constructor(x: number) { this.onlyInCtor = x; }
}
// valid.ts
class C {
  private readonly neverMutated = 1;
}
📜 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 46a8e93 and a595733.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.js.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • .changeset/grumpy-monkeys-tap.md (1 hunks)
  • crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs (2 hunks)
  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
.changeset/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

.changeset/*.md: Create changesets with just new-changeset; store them in .changeset/ with correct frontmatter (package keys and change type).
In changeset descriptions, follow content conventions: user-facing changes only; past tense for what you did; present tense for current behavior; link issues for fixes; link rules/assists; include representative code blocks; end every sentence with a period.
When adding headers in a changeset, only use #### or ##### levels.

Files:

  • .changeset/grumpy-monkeys-tap.md
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/specs/style/useReadonlyClassProperties/valid.js
  • crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs
crates/biome_*/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place core crates under /crates/biome_*/

Files:

  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.js
  • crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs
**/tests/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place test files under a tests/ directory in each crate

Files:

  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/valid.js
**/*.{rs,toml}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

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

Files:

  • crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs
🧠 Learnings (3)
📚 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/specs/style/useReadonlyClassProperties/valid.js
📚 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/src/lint/style/use_readonly_class_properties.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/src/lint/style/use_readonly_class_properties.rs
⏰ 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: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_js_parser)
🔇 Additional comments (2)
crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs (2)

13-14: Import of JsFileSource looks right.

This is the correct import to inspect source language in the rule context.


142-146: TSX is correctly treated as TypeScript by is_typescript()
The is_typescript() method matches any Language::TypeScript variant—including .tsx via JsFileSource::tsx()—so this rule will run on both .ts and .tsx files. No changes needed.

Copy link

codspeed-hq bot commented Aug 23, 2025

CodSpeed Performance Report

Merging #7302 will not alter performance

Comparing unvalley:use-readonly-class-properties-only-ts (72a82b7) with main (46a8e93)1

Summary

✅ 133 untouched benchmarks

Footnotes

  1. No successful run was found on main (8771b84) during the generation of this report, so 46a8e93 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

fn run(ctx: &RuleContext<Self>) -> Self::Signals {
let source_type = ctx.source_type::<JsFileSource>().language();
if !source_type.is_typescript() {
return Box::new([]);
Copy link
Member

Choose a reason for hiding this comment

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

The bot suggestion seems sound

@unvalley unvalley merged commit 2af2380 into biomejs:main Aug 23, 2025
30 checks passed
@github-actions github-actions bot mentioned this pull request Aug 23, 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.

💅 useReadonlyClassProperties want to add readonly on javascript files

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载