Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@YTomm
Copy link
Contributor

@YTomm YTomm commented Nov 11, 2025

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 checkAllProperties option enabled, the suggested code sometimes contains an unwanted new line.

  • example from the issue
    38 38 │   
    39 39 │   export class ErrorResponse extends Error {
    40    │ - → statusCode:·number;
       40 │ + → readonly·
       41 │ + → statusCode:·number;
    41 42 │   
    42 43 │     readonly rawCode: ErrorResponseOptions["rawCode"];

The cause is that AnyJsClassMemberName::JsLiteralMemberName retains leading trivia after inserting the readonly modifier, so I removed them.

Test Plan

Added new tests for this issue's case.

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

🦋 Changeset detected

Latest commit: 312b1ce

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

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Nov 11, 2025
Comment on lines +170 to +176
i Unsafe fix: Add readonly decorator.
6 │ → readonly·prop4:·string;
│ +++++++++
```

Copy link
Contributor Author

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 │   

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Walkthrough

Renames 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

  • siketyan
  • dyc3

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: removing an unexpected newline when adding readonly to class properties.
Description check ✅ Passed The description clearly explains the bug, root cause, and solution, with a concrete example and test plan provided.
Linked Issues check ✅ Passed The changes directly address issue #7948 by removing leading trivia from JsLiteralMemberName to prevent unwanted newlines when inserting readonly.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the readonly formatting issue: function rename, trivia handling, test additions, and changeset documentation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 275bc3d and 312b1ce.

📒 Files selected for processing (1)
  • .changeset/fuzzy-dragons-invent.md (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 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-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/Cargo.toml : Declare the dependency `biome_js_formatter = { version = "0.0.1", path = "../biome_js_formatter" }` for internal installation

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
⏰ 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)
  • 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-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Validate rules documentation
🔇 Additional comments (1)
.changeset/fuzzy-dragons-invent.md (1)

1-5: Changeset entry looks good.

Well done incorporating the previous feedback from dyc3. The entry properly documents the fix with the issue link, lint rule name, and clear description. Ready to go.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

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 (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 #privateProperty names, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8b93578 and 2ccf35b.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/style/useReadonlyClassProperties/invalid_checkAllPropertiesTrue.ts.snap is excluded by !**/*.snap and 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.

Copy link
Contributor

@dyc3 dyc3 left a 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-hq
Copy link

codspeed-hq bot commented Nov 11, 2025

CodSpeed Performance Report

Merging #8075 will not alter performance

Comparing YTomm:fix/use-readonly-class-properties (312b1ce) with main (f1d5725)1

Summary

✅ 58 untouched
⏩ 95 skipped2

Footnotes

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

  2. 95 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Member

@siketyan siketyan left a 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?

@YTomm
Copy link
Contributor Author

YTomm commented Nov 11, 2025

@siketyan I will modify the comments based on the coderabbitai comment

@YTomm
Copy link
Contributor Author

YTomm commented Nov 11, 2025

@dyc3 added the changeset doc. 7147489
Are the format and content suitable?

@siketyan revised the code comment and the function name 7147489

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: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ccf35b and 7147489.

📒 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 JsLiteralMemberName correctly 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.

"@biomejs/biome": minor
---

The linter, with `checkAllProperties` enabled, was fixed and remove unwanted new line.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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".

@YTomm YTomm requested review from dyc3 and siketyan November 11, 2025 16:19
@ematipico ematipico merged commit e403868 into biomejs:main Nov 11, 2025
18 checks passed
@github-actions github-actions bot mentioned this pull request Nov 11, 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.

🐛 checkAllProperties option for useReadonlyClassProperties has error in formatting

4 participants