Skip to content

Commit 4a9139b

Browse files
hirokiokada77dyc3
andauthored
fix(noParameterAssign): prevent false positive when parameter is used as R-value (#8259)
Co-authored-by: Carson McManus <[email protected]>
1 parent f1e4696 commit 4a9139b

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

.changeset/light-mugs-speak.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#8254](https://github.com/biomejs/biome/issues/8254): The `noParameterAssign` rule with `propertyAssignment: "deny"` was incorrectly reporting an error when a function parameter was used on the right-hand side of an assignment to a local variable's property.
6+
7+
The rule should only flag assignments that modify the parameter binding or its properties (L-value), not the use of its value.
8+
9+
**Valid:**
10+
11+
```js
12+
(input) => {
13+
const local = { property: 0 };
14+
local.property = input;
15+
};
16+
```

crates/biome_js_analyze/src/lint/style/no_parameter_assign.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,30 @@ impl Rule for NoParameterAssign {
148148

149149
match left.as_any_js_assignment()? {
150150
AnyJsAssignment::JsComputedMemberAssignment(assignment) => {
151-
assignment.object().ok()
151+
if assignment
152+
.object()
153+
.ok()?
154+
.get_callee_object_name()?
155+
.token_text_trimmed()
156+
== binding.name_token().ok()?.token_text_trimmed()
157+
{
158+
return assignment.object().ok();
159+
}
160+
161+
None
152162
}
153163
AnyJsAssignment::JsStaticMemberAssignment(assignment) => {
154-
assignment.object().ok()
164+
if assignment
165+
.object()
166+
.ok()?
167+
.get_callee_object_name()?
168+
.token_text_trimmed()
169+
== binding.name_token().ok()?.token_text_trimmed()
170+
{
171+
return assignment.object().ok();
172+
}
173+
174+
None
155175
}
156176
_ => None,
157177
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// should not generate diagnostics
2+
function copyParamValueToLocalProperty(input) {
3+
const local = { a: 0, b: 0 };
4+
local.a = input;
5+
local["b"] = input;
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: parameterMutationDenyValid.js
4+
---
5+
# Input
6+
```js
7+
// should not generate diagnostics
8+
function copyParamValueToLocalProperty(input) {
9+
const local = { a: 0, b: 0 };
10+
local.a = input;
11+
local["b"] = input;
12+
}
13+
14+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json",
3+
"linter": {
4+
"rules": {
5+
"style": {
6+
"noParameterAssign": {
7+
"level": "error",
8+
"options": {
9+
"propertyAssignment": "deny"
10+
}
11+
}
12+
}
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)