-
-
Notifications
You must be signed in to change notification settings - Fork 760
fix: remove unexpected new line when adding a readonly class property #8075
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: remove unexpected new line when adding a readonly class property #8075
Conversation
🦋 Changeset detectedLatest commit: 312b1ce 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 |
| i Unsafe fix: Add readonly decorator. | ||
| 6 │ → readonly·prop4:·string; | ||
| │ +++++++++ | ||
| ``` | ||
|
|
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 output when testing on main branch
165 │+ i Unsafe fix: Add readonly decorator.
166 │+
167 │+ 4 4 │ protected prop2: string;
168 │+ 5 5 │ public prop3: string;
169 │+ 6 │ - → prop4:·string;
170 │+ 6 │ + → readonly·
171 │+ 7 │ + → prop4:·string;
172 │+ 7 8 │ }
173 │+ 8 9 │
WalkthroughRenames extract_property_member_name_trimmed_whitespace to extract_class_member_name_trimmed_whitespace and updates its call site. The renamed function now also handles JsLiteralMemberName by trimming leading trivia from the underlying value token and replacing that token. Comments/docs were updated to reference trimming leading trivia generally. A test was modified to add a new public class field that affects the useReadonlyClassProperties lint when checkAllProperties is enabled. No exported/public API changes. Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (3)📚 Learning: 2025-08-05T14:43:29.581ZApplied to files:
📚 Learning: 2025-10-15T09:22:46.002ZApplied to files:
📚 Learning: 2025-09-25T12:32:59.003ZApplied to files:
⏰ 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). (13)
🔇 Additional comments (1)
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. Comment |
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: 0
🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs (1)
356-358: Consider updating the function comment.The comment mentions only
#privatePropertynames, but the function now also handles literal member names. A brief update would improve clarity.Apply this diff to update the comment:
-/// Removes leading whitespace from `#privateProperty` names. Without this, the name might include -/// unwanted whitespace (e.g., "\n #privateProperty"). This ensures that when adding modifiers like -/// `readonly`, they are appended correctly without being affected by the whitespace. +/// Removes leading whitespace from class member names. Without this, the name might include +/// unwanted whitespace (e.g., "\n #privateProperty" or "\n statusCode"). This ensures that when +/// adding modifiers like `readonly`, they are appended correctly without being affected by the whitespace.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/invalid_checkAllPropertiesTrue.ts.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (2)
crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs(1 hunks)crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/invalid_checkAllPropertiesTrue.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/type_info.rs : Add new TypeScript type support by extending the TypeData enum rather than introducing parallel structures.
Applied to files:
crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs (1)
crates/biome_js_analyze/src/react/components.rs (4)
name(428-435)name(465-489)name(531-546)value(548-553)
🔇 Additional comments (2)
crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/invalid_checkAllPropertiesTrue.ts (1)
6-6: Good test case for the reported issue.The addition of a default public property effectively tests the fix for the unwanted newline issue when adding the readonly modifier.
crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs (1)
370-376: Fix correctly mirrors the existing pattern.The implementation properly extends trivia removal to literal member names, following the same approach used for private class member names. This should resolve the unwanted newline issue.
dyc3
left a comment
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.
Nicely done! Can you add a changeset? (make sure to write it in the past tense, and link the issue that is being fixed)
CodSpeed Performance ReportMerging #8075 will not alter performanceComparing Summary
Footnotes
|
siketyan
left a comment
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.
Does it keep comments as-is that is attached to the node?
|
@siketyan I will modify the comments based on the coderabbitai comment |
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: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/fuzzy-dragons-invent.md(1 hunks)crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs(3 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
Repo: biomejs/biome PR: 7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.
Applied to files:
.changeset/fuzzy-dragons-invent.md
📚 Learning: 2025-09-25T12:32:59.003Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7593
File: crates/biome_service/src/workspace/server.rs:1306-1306
Timestamp: 2025-09-25T12:32:59.003Z
Learning: In the biomejs/biome project, do not flag compilation errors during code review as they are handled by the existing test infrastructure and CI. Focus on other code quality aspects instead.
Applied to files:
.changeset/fuzzy-dragons-invent.md
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs (1)
crates/biome_js_analyze/src/react/components.rs (4)
name(428-435)name(465-489)name(531-546)value(548-553)
🔇 Additional comments (2)
crates/biome_js_analyze/src/lint/style/use_readonly_class_properties.rs (2)
222-222: LGTM! Call site updated correctly.The function call has been properly updated to use the new name.
356-379: Excellent fix for the reported issue!The function rename better reflects its broader scope, and the new handling for
JsLiteralMemberNamecorrectly mirrors the pattern used for private class members. By trimming leading trivia from the value token, this prevents the unwanted newline that was being inserted before the readonly modifier.The documentation update from "whitespace" to "leading trivia" is also more accurate.
.changeset/fuzzy-dragons-invent.md
Outdated
| "@biomejs/biome": minor | ||
| --- | ||
|
|
||
| The linter, with `checkAllProperties` enabled, was fixed and remove unwanted new line. |
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.
Fix grammar in changeset description.
The phrase "was fixed and remove" is grammatically incorrect.
Apply this diff to fix the grammar:
-The linter, with `checkAllProperties` enabled, was fixed and remove unwanted new line.
+The linter, with `checkAllProperties` enabled, was fixed to remove unwanted newlines.Note: Changed "new line" to "newlines" for consistency with common usage.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| The linter, with `checkAllProperties` enabled, was fixed and remove unwanted new line. | |
| The linter, with `checkAllProperties` enabled, was fixed to remove unwanted newlines. |
🤖 Prompt for AI Agents
In .changeset/fuzzy-dragons-invent.md around line 5, fix the grammatical error
in the changeset sentence by replacing "The linter, with `checkAllProperties`
enabled, was fixed and remove unwanted new line." with a correct form such as
"The linter, with `checkAllProperties` enabled, was fixed and removed unwanted
newlines." ensuring "remove" becomes "removed" and "new line" becomes
"newlines".
Co-authored-by: Carson McManus <[email protected]>
Co-authored-by: Carson McManus <[email protected]>
fix: #7948
This is my first PR for OSS, so please feel free to point it out if anything seems off.
I consulted ChatGPT to understand the codebase but the solution was fully authored manually by myself.
Summary
With
checkAllPropertiesoption enabled, the suggested code sometimes contains an unwanted new line.The cause is that
AnyJsClassMemberName::JsLiteralMemberNameretains leading trivia after inserting thereadonlymodifier, so I removed them.Test Plan
Added new tests for this issue's case.