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
16 changes: 16 additions & 0 deletions .changeset/light-mugs-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@biomejs/biome": patch
---

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.

The rule should only flag assignments that modify the parameter binding or its properties (L-value), not the use of its value.

**Valid:**

```js
(input) => {
const local = { property: 0 };
local.property = input;
};
```
24 changes: 22 additions & 2 deletions crates/biome_js_analyze/src/lint/style/no_parameter_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,30 @@ impl Rule for NoParameterAssign {

match left.as_any_js_assignment()? {
AnyJsAssignment::JsComputedMemberAssignment(assignment) => {
assignment.object().ok()
if assignment
.object()
.ok()?
.get_callee_object_name()?
.token_text_trimmed()
== binding.name_token().ok()?.token_text_trimmed()
{
return assignment.object().ok();
}

None
}
AnyJsAssignment::JsStaticMemberAssignment(assignment) => {
assignment.object().ok()
if assignment
.object()
.ok()?
.get_callee_object_name()?
.token_text_trimmed()
== binding.name_token().ok()?.token_text_trimmed()
{
return assignment.object().ok();
}

None
}
_ => None,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// should not generate diagnostics
function copyParamValueToLocalProperty(input) {
const local = { a: 0, b: 0 };
local.a = input;
local["b"] = input;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: parameterMutationDenyValid.js
---
# Input
```js
// should not generate diagnostics
function copyParamValueToLocalProperty(input) {
const local = { a: 0, b: 0 };
local.a = input;
local["b"] = input;
}

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json",
"linter": {
"rules": {
"style": {
"noParameterAssign": {
"level": "error",
"options": {
"propertyAssignment": "deny"
}
}
}
}
}
}