-
-
Notifications
You must be signed in to change notification settings - Fork 714
fix(lint/useReadonlyClassProperties): skip rule for JavaScript files #7302
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
fix(lint/useReadonlyClassProperties): skip rule for JavaScript files #7302
Conversation
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.
WalkthroughAdds an early guard in UseReadonlyClassProperties::run to skip non-TypeScript sources by checking Assessment against linked issues
Suggested reviewers
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 detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
🦋 Changeset detectedLatest commit: 72a82b7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
There was a problem hiding this 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
orvalid.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.
⛔ 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 withjust 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 byis_typescript()
Theis_typescript()
method matches anyLanguage::TypeScript
variant—including.tsx
viaJsFileSource::tsx()
—so this rule will run on both.ts
and.tsx
files. No changes needed.
CodSpeed Performance ReportMerging #7302 will not alter performanceComparing Summary
Footnotes |
fn run(ctx: &RuleContext<Self>) -> Self::Signals { | ||
let source_type = ctx.source_type::<JsFileSource>().language(); | ||
if !source_type.is_typescript() { | ||
return Box::new([]); |
There was a problem hiding this comment.
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
Summary
Closes #7301
useReadonlyClassProperties should skip JavaScript files, because of readonly modifier is TypeScript only.
Test Plan
Added a snapshot
Docs