src/content/docs/linter/rules/no-parameter-assign.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/style/noParameterAssign`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`no-param-reassign`](https://eslint.org/docs/latest/rules/no-param-reassign){
"linter": {
"rules": {
"style": {
"noParameterAssign": "error"
}
}
}
}
Disallow reassigning function parameters.
Assignment to function parameters can be misleading and confusing,
as modifying parameters will also mutate the arguments object.
It is often unintended and indicative of a programmer error.
function f(param) {
param = 13;
}
function f(param) {
param++;
}
function f(param) {
for (param of arr) {}
}
class C {
constructor(readonly prop: number) {
prop++;
}
}
function f(param) {
let local = param;
}
The noParameterAssign rule can be configured using the propertyAssignment option, which determines whether property assignments on function parameters are allowed or denied. By default, propertyAssignment is set to allow.
{
"options": {
"propertyAssignment": "allow"
}
}
{
"linter": {
"rules": {
"style": {
"noParameterAssign": {
"options": {
"propertyAssignment": "allow"
}
}
}
}
}
}
function update(obj) {
obj.key = "value"; // No diagnostic
}
{
"linter": {
"rules": {
"style": {
"noParameterAssign": {
"options": {
"propertyAssignment": "deny"
}
}
}
}
}
}
function update(obj) {
obj.key = "value"; // Diagnostic: Assignment to a property of function parameter is not allowed.
}