Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/use_readonly_class_properties_nested_assignment_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@biomejs/biome": patch
---

Fixed [#7310](https://github.com/biomejs/biome/issues/7310): [`useReadonlyClassProperties`](https://biomejs.dev/linter/rules/use-readonly-class-properties/) correctly handles nested assignments, avoiding false positives when a class property is assigned within another assignment expression.

Example of code that previously triggered a false positive but is now correctly ignored:

```ts
class test {
private thing: number = 0; // incorrectly flagged

public incrementThing(): void {
const temp = {x: 0};
temp.x = this.thing++;
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,24 @@ export class ToastService {
this.activeToasts.push({id, message, type, autoClose});
}
}

class TestIncrementInAssignment {
private thing: number = 0;

public incrementThing(): void {
const temp = { x: 0 };
temp.x = this.thing++;
}
}

class TesAssignmentInNestedCallback {
private thing: any;

public doStuff(): void {
ui.showText("example", {
callback: () => {
this.thing = x;
},
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 146
assertion_line: 152
expression: valid.ts
---
# Input
Expand Down Expand Up @@ -672,4 +672,25 @@ export class ToastService {
}
}

class TestIncrementInAssignment {
private thing: number = 0;

public incrementThing(): void {
const temp = { x: 0 };
temp.x = this.thing++;
}
}

class TesAssignmentInNestedCallback {
private thing: any;

public doStuff(): void {
ui.showText("example", {
callback: () => {
this.thing = x;
},
});
}
}

```
Loading