Understanding ESLint's `no-param-reassign` Rule for Clearer Functions

When you define a function, you can specify variables that the function will receive as input. These are called parameters. The no-param-reassign rule discourages directly changing the value of these parameters within the function.

There are two reasons for this:

  • Clarity: If you modify a parameter inside the function, it can be confusing for someone reading the code to understand what the function does. They might expect the parameter value to stay the same throughout the function.
  • Unexpected behavior: In JavaScript, there's a concept called the arguments object. This object holds the values of all the arguments passed to a function. If you change a parameter inside the function, it can also unintentionally modify the arguments object, leading to unexpected results.

Are there exceptions?

There are some cases where reassigning a parameter might be necessary. For instance, you might be working with an object and want to modify one of its properties. In these cases, ESLint provides ways to configure the no-param-reassign rule to allow such modifications while still catching unintended changes.

Strict mode and no-param-reassign

If your code is written in strict mode (a more secure way to write JavaScript), the no-param-reassign rule becomes less important. Strict mode already offers some protections against unintended modifications of the arguments object.

  • You'll see an error message from ESLint when you try to directly reassign a parameter value within a function. This typically looks like no-param-reassign: Assignment to function parameter '<parameter_name>' .

Troubleshooting:

Configure no-param-reassign : ESLint allows some configuration for this rule. You can:

  • Ignore Specific Parameters: If certain parameters are meant to be modified (like state in state management libraries), you can configure no-param-reassign to ignore those specific names.
  • Allow Property Modifications: You can allow modifications to properties of objects passed as parameters while still disallowing complete reassignment.

Code Examples for no-param-reassign Rule

This code triggers a no-param-reassign error because it tries to change the value of the x parameter directly:

Fix: Working with the Parameter's Value

Here, we avoid the error by using the original parameter value ( num ) within the function:

Error: Modifying an Object Property

This code attempts to modify a property ( name ) of the object passed as a parameter, which can also trigger the error in some configurations:

Fix: Ignoring Property Modifications (Configuration)

If modifying object properties is intended, you can configure no-param-reassign to allow it:

Allowed Scenario: Working with Copies (Array)

This code demonstrates a case where creating a copy of the parameter (array) is necessary for modification:

Destructuring with Default Values:

  • When defining the function, you can use destructuring with default values for parameters. This allows you to provide a fallback value if no argument is passed, avoiding the need to reassign later.

Early Return with Modified Copy:

  • If you need to modify data passed as a parameter (like an object or array), consider creating a copy early on and working with the copy. Then, return the modified copy from the function.

Functional Programming Techniques:

Purpose:Controls which imports are allowed in your JavaScript code.Helps enforce coding standards and prevent potential issues

What is ESLint?ESLint is a popular tool for JavaScript developers that helps enforce coding style and identify potential errors

What it does: It checks your code for any variables that you use but haven't properly declared using var, let, or const

Having unused variables can clutter up your code and make it harder to read for you and other programmers. It also might indicate a bug if a variable was meant to be used but isn't. The no-unused-vars rule helps you find these unused variables and clean up your code

Here's a breakdown of how it works:What it catches: The rule flags any instance where you reference a variable, function

Here's what the rule considers "useless":Simply re-throwing the error: If your catch block just catches an error and then throws it again without any modification or handling

Here's how it works:Escapes in Strings: In JavaScript, backslashes (\) are used to escape characters that might otherwise have special meanings within strings

Disallow Reassignment of Function Parameters (no-param-reassign)

Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

Rule Details

This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

Examples of incorrect code for this rule:

Examples of correct code for this rule:

This rule takes one option, an object, with a boolean property "props" and an array "ignorePropertyModificationsFor" . "props" is false by default. If "props" is set to true , this rule warns against the modification of parameter properties unless they’re included in "ignorePropertyModificationsFor" , which is an empty array by default.

Examples of correct code for the default { "props" : false } option:

Examples of incorrect code for the { "props" : true } option:

Examples of correct code for the { "props" : true } option with "ignorePropertyModificationsFor" set:

When Not To Use It

If you want to allow assignment to function parameters, then you can safely disable this rule.

Further Reading

  • JavaScript: Don’t Reassign Your Function Arguments

This rule was introduced in ESLint 0.18.0.

  • Rule source
  • Documentation source

Disallow Reassignment of Function Parameters (no-param-reassign)

Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

Rule Details

This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

Examples of incorrect code for this rule:

Examples of correct code for this rule:

This rule takes one option, an object, with a boolean property "props" , and arrays "ignorePropertyModificationsFor" and "ignorePropertyModificationsForRegex" . "props" is false by default. If "props" is set to true , this rule warns against the modification of parameter properties unless they're included in "ignorePropertyModificationsFor" or "ignorePropertyModificationsForRegex" , which is an empty array by default.

Examples of correct code for the default { "props": false } option:

Examples of incorrect code for the { "props": true } option:

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsForRegex" set:

When Not To Use It

If you want to allow assignment to function parameters, then you can safely disable this rule.

Further Reading

  • JavaScript: Don’t Reassign Your Function Arguments

This rule was introduced in ESLint 0.18.0.

  • Rule source
  • Documentation source

© OpenJS Foundation and other contributors Licensed under the MIT License. https://eslint.org/docs/rules/no-param-reassign

I maginative T hinking .ca

A developers blog

What the Heck is the deal with no-param-reassign

Hey Brad I’m getting a linter error no-param-reassign what is up with that?

The thing to remember about ECMAScript is that it passes by reference.

So when you pass a variable into a function you are not passing the variable value but a reference to the location in memory where the value is located.

When a variable holds a primitive (Number or String) and you re-assign its value your pointing it to a new memory location.

When you modify a variable which holds a primitive value you are changing the memory location stored in the variable.

When you assign the value of one variable to another you are assigning to the second variable the value of the memory location that the first variable is pointing to.

Modifying the second variable will change the memory location the variable points to without affecting the first variable.

But with Objects or Arrays the variable points to a memory location which it self holds references to other memory locations. Often its the child memory locations you end up modifying and not the reference to the object. This is where you can start getting into trouble because you end up changing the value of the callers variable.

Notice here that x and u point to the same object reference. Thus if we modify one of x's properties it means we will also be modifying u's property.

When dealing with Arrays or Objects you need to remember ECMAScript passes by reference .

What this means when it comes to functions is that when you pass a value into a function which you stored in a variable the function invocation will copy the reference address of your object into a parameter variable to be used by the function. If the value is an object or an array and you modify that parameter you will be modifying the callers variable.

In the above both u and x will point to the same object and both will have the newProp property since the parameter user was pointing to the same memory location as u .

How to Make a Function immutable

The first thought when people see the no-param-reassign error is to copy the parameter value into a locally scoped variable.

This does not work as we discussed above; both user and userP will be pointing to the same memory location. It will 100% remove the no-param-reassign error but you will still be mutating the callers variable.

How do we ensure we are not modifying the origin value? We need to clone the object.

Above user and userP will point to two different memory locations. The user variable will point to a different memory location which has an object in it and that object will have properties which point to the same memory location as the properties on the object referenced by userP .

In ES2018 they add the Spread operator for Object Literals so instead of using Object.assign() you can perform shallow copies with const user = {...userP};

Because we now have a completely different object we can add properties to it and update the values in existing properties (we'll update the properties attached to our object to point to different memory locations) without affecting the callers object.

The thing to keep in mind here is that we just did what is known as a shallow copy. A shallow copy just copies the values from the properties on the parent object and does not copy values of nested objects.

If for example we had:

The variables u and x will point to different memory locations however u.obj and x.obj will point to the same location. We can reassign x.obj to a new value (change the memory location it points to) without affecting u , however; attaching new properties to x.obj or changing x.obj.hello will affect both u and x .

In cases where the object in question has nested object and you need to modify the nested objects you need to perform a deep clone which will generate new object in memory for the entire object hierarchy. In our case that would mean we would get different objects for both u and u.obj assigned to x and x.obj respectively. Just keep in mind that deep clones have a higher performance hit then shallow clones as one might expect so best to only do deep clones if you really need to otherwise use shallow clones if you can get away with it.

So that is what the deal is with the no-param-reassign linter error. It warns you that your function might cause unexpected side effects in the callers code because you could be modifying a shared memory location due to ECMAScript's pass by reference design.

Until next time think imaginatively and design creatively

If you liked this post Share it.

  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Google+ (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to email this to a friend (Opens in new window)

My interest in computer programming started back in high school and Software Development has remained a hobby of mine ever since. I graduated as a Computer Engineering Technologist and have been working as a Software Developer for many years. I believe that software is crafted; understanding that how it is done is as important as getting it done. I enjoy the aesthetics in crafting elegant solutions to complex problems and revel in the knowledge that my code is maintainable and thus, will have longevity. I hold the designation Certified Technician (C.Tech.) with the Ontario Association of Computer Engineering Technicians and Technologists (OACETT), have been certified as a Professional Scrum Master level 1 (PSM I) and as a Professional Scrum Developer level 1 (PSD I) by Scrum.org as well as designated as an Officially Certified Qt Developer by the Qt Company. For more on my story check out the about page here

Feel free to write a reply or comment. Cancel reply

no-param-reassign

Disallows reassignment of function parameters.

Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

Rule Details

This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

Examples of incorrect code for this rule:

Examples of correct code for this rule:

This rule takes one option, an object, with a boolean property "props" , and arrays "ignorePropertyModificationsFor" and "ignorePropertyModificationsForRegex" . "props" is false by default. If "props" is set to true , this rule warns against the modification of parameter properties unless they're included in "ignorePropertyModificationsFor" or "ignorePropertyModificationsForRegex" , which is an empty array by default.

Examples of correct code for the default { "props": false } option:

Examples of incorrect code for the { "props": true } option:

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsForRegex" set:

When Not To Use It

If you want to allow assignment to function parameters, then you can safely disable this rule.

Further Reading

  • https://spin.atomicobject.com/2011/04/10/javascript-don-t-reassign-your-function-arguments/

This rule was introduced in ESLint 0.18.0.

  • Rule source
  • Test source
  • Documentation source

no-param-reassign

Disallow reassigning function parameters

Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

Rule Details

This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

Examples of incorrect code for this rule:

Examples of correct code for this rule:

This rule takes one option, an object, with a boolean property "props" , and arrays "ignorePropertyModificationsFor" and "ignorePropertyModificationsForRegex" . "props" is false by default. If "props" is set to true , this rule warns against the modification of parameter properties unless they’re included in "ignorePropertyModificationsFor" or "ignorePropertyModificationsForRegex" , which is an empty array by default.

Examples of correct code for the default { "props": false } option:

Examples of incorrect code for the { "props": true } option:

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsForRegex" set:

When Not To Use It

If you want to allow assignment to function parameters, then you can safely disable this rule.

This rule was introduced in ESLint v0.18.0.

Further Reading

JavaScript: Don’t Reassign Your Function Arguments

  • Rule source
  • Tests source

© OpenJS Foundation and other contributors Licensed under the MIT License. https://eslint.org/docs/latest/rules/no-param-reassign

Get the Reddit app

This subreddit is for anyone who wants to learn JavaScript or help others do so. Questions and posts about frontend development in general are welcome, as are all posts pertaining to JavaScript on the backend.

Why eslint throws "Assignment to property of function parameter 'element'." for this?

I started learning javascript a week ago. Started using eslint yesterday and it's very useful. I have been trying this part of the code for sometime now and eslint keeps throwing Assignment to property of function parameter 'element'. Here is the code;

Before this I was doing something like this;

I know eslint isn't showing error for nothing so I would like to know what's reason and how it should be done.

And I have another eventListner with same pattern but that changes the opacity to 0 and pointerEvents to 'none'. So is there a way to do that using ternary operator or should I just stick to if else for that?Thanks and lemme know if there anything else I can improve.

By continuing, you agree to our User Agreement and acknowledge that you understand the Privacy Policy .

Enter the 6-digit code from your authenticator app

You’ve set up two-factor authentication for this account.

Enter a 6-digit backup code

Create your username and password.

Reddit is anonymous, so your username is what you’ll go by here. Choose wisely—because once you get a name, you can’t change it.

Reset your password

Enter your email address or username and we’ll send you a link to reset your password

Check your inbox

An email with a link to reset your password was sent to the email address associated with your account

Choose a Reddit account to continue

noParameterAssign

Diagnostic Category: lint/style/noParameterAssign

  • JavaScript (and super languages)

Since : v1.0.0

  • Same as: no-param-reassign

Disallow reassigning function parameters.

Assignment to a 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.

In contrast to the ESLint rule, this rule cannot be configured to report assignments to a property of a parameter.

Related links

  • Disable a rule
  • Configure the rule fix
  • Rule options
  • Arrow function should not return assignment. eslint no-return-assign

avatar

Last updated: Mar 7, 2024 Reading time · 4 min

banner

# Table of Contents

  • Split the assignment and return statement into 2 lines
  • Solving the error in a React.js application
  • Trying to return a comparison from a function
  • Configuring the no-return-assign ESLint rule
  • Disabling the no-return-assign ESLint rule globally
  • Disabling the no-return-assign ESLint rule for a single line
  • Disabling the no-return-assign ESLint rule for an entire file

# Arrow function should not return assignment. eslint no-return-assign

The ESLint error "Arrow function should not return assignment. eslint no-return-assign" is raised when you return an assignment from an arrow function.

To solve the error, wrap the assignment in curly braces, so it doesn't get returned from the arrow function.

arrow function should not return assignment eslint no return assign

  • Return statement should not contain assignment. eslint no-return-assign

return statement should not contain assignment no return assign

Here is an example of how the error occurs.

The issue in the example is that we're returning an assignment from an arrow function.

If you need to mutate a value that is located outside the function, use curly braces and then assign the value in the function's body.

The code sample above doesn't cause any warnings because the arrow function no longer returns the assignment.

Make sure you aren't returning an assignment explicitly as this also causes the error.

You can remove the return statement and assign the value to resolve the issue.

# Split the assignment and return statement into 2 lines

The error also occurs when you try to combine an assignment and a return statement into one.

To resolve the issue, assign a value to the variable on one line and use a return statement on the next.

The example above uses the Array.reduce method.

Notice that we first assign a value to the accumulator variable and then on the next line, return the variable.

Make sure you don't combine the two steps into a single line as it makes your code difficult to read.

# Solving the error in a React.js application

The error is often caused when using refs in older versions of React.js.

The following code causes the error.

To resolve the issue, wrap the assignment in curly braces, so it isn't returned from the arrow function.

Make sure you don't explicitly return the assignment as well.

# Trying to return a comparison from a function

If you meant to return a comparison from a function, use triple equals ( === ) and not a single equal sign.

Three equal signs === are used to compare values and a single equal = sign is used to assign a value to a variable.

# Configuring the no-return-assign ESLint rule

The no-return-assign ESLint rule has 2 values:

  • except-parens (default) - disallow assignments unless they are enclosed in parentheses.
  • always - disallow all assignments in return statements.

The following examples are all valid if you use the except-parens value.

If the rule's value is set to always , then you all assignments in return statements are disallowed.

# Disabling the no-return-assign ESLint rule globally

If you want to disable the no-return-assign ESLint rule globally, you have to edit your .eslintrc.js config file.

disable no return assign eslint rule

If you use a .eslintrc or .eslintrc.json file, make sure to double-quote all properties and values.

Make sure you don't have any trailing commas if you write your config in a JSON file.

# Disabling the no-return-assign ESLint rule for a single line

If you want to disable the no-return-assign rule for a single line, use the following comment.

Make sure to add the comment directly above the line that causes the warning.

# Disabling the no-return-assign ESLint rule for an entire file

If you want to disable the rule for an entire file, use the following comment instead.

Make sure to add the comment at the top of the file or at least above any functions that return assignments.

You can use the same approach to only disable the rule for a specific function.

The first ESLint comment disables the rule and the second comment enables it.

This is why the function on the last line causes the error - it is placed after the comment that enables the no-return-assign rule.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

  • React ESLint Error: X is missing in props validation
  • eslint is not recognized as an internal or external command
  • ESLint: Unexpected lexical declaration in case block [Fixed]
  • ESLint error Unary operator '++' used no-plusplus [Solved]
  • ESLint Prefer default export import/prefer-default-export
  • Assignment to property of function parameter no-param-reassign
  • Expected parentheses around arrow function argument arrow-parens
  • ESLint: A form label must be associated with a control

book cover

Borislav Hadzhiev

Web Developer

buy me a coffee

Copyright © 2024 Borislav Hadzhiev

no-param-reassign

Disallow reassigning function parameters

对作为函数参数声明的变量进行赋值可能会产生误导并导致混乱的行为,因为修改函数参数也会改变 arguments 对象。通常情况下,对函数参数的赋值是无意的,表明了一个错误或程序员的错误。

这条规则也可以被配置为在修改函数参数时失败。参数的副作用会导致反直觉的执行流程,使错误难以追踪。

这条规则的目的是防止因修改或重新分配函数参数而引起的非预期行为。

使用此规则的 错误 示例:

使用此规则的 正确 示例:

这个规则有一个选项,是一个对象,有一个布尔属性 "props" 和数组 "ignorePropertyModificationsFor" 和 "ignorePropertyModificationsForRegex" 。 "props" 默认为 false 。如果 "props" 设置为 true ,本规则警告不要修改参数属性,除非它们被包含在 "ignorePropertyModificationsFor" 或 "ignorePropertyModificationsForRegex" 中,默认为空数组。

使用默认的 { "props": false } 选项的 正确 示例:

使用 { "props": true } 选项的 错误 示例:

设置了 "ignorePropertyModificationsFor" 的 { "props": true } 选项的**正确的代码示例:

设置了 "ignorePropertyModificationsForRegex" 的 { "props": true } 选项的**正确的代码示例:

如果你想允许对函数参数进行赋值,你可以安全地禁用此规则。

This rule was introduced in ESLint v0.18.0.

Further Reading

Avatar image for spin.atomicobject.com

  • Rule source
  • Tests source

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with eslint no-param-reassign #189

@brummelte

brummelte commented Sep 14, 2018 • edited Loading

I don't want to disable the eslint rule "no-param-reassign" globally, because it prevents errors.

So this seems to be the best way to use immer with that rule enabled:

nextState = produce(baseState, (draftState) => { /* eslint-disable no-param-reassign */ draftState.test = "New value"; /* eslint-enable no-param-reassign */ });

There is a way to specify "ignorePropertyModificationsFor" for that eslint rule ( ). So draftState could be ignored. But that would only exclude that name.

Is there a better way without disabling that rule?

  • 👍 13 reactions
  • ❤️ 1 reaction

@mweststrate

mweststrate commented Sep 14, 2018

I don't think your example is a param reassign and the rule shouldn't trigger on it

Sorry, something went wrong.

brummelte commented Sep 14, 2018

You are correct, I just copied it from your example. But the question stays the same:

nextState = produce(baseState, (draftState) => { /* eslint-disable no-param-reassign */ draftState.test = "New value"; /* eslint-enable no-param-reassign */ });

mweststrate commented Sep 14, 2018 via email

>, or mute the thread < > .
  • 👎 51 reactions

It is with the option .

Which the airbnb preset uses:

  • 👍 5 reactions
  • 👍 2 reactions
  • 👎 31 reactions
  • 😕 4 reactions

@brummelte

< >. — You are receiving this because you commented. Reply to this email directly, view it on GitHub < >, or mute the thread < > .

@davalapar

davalapar commented Sep 15, 2018

I also don't like disabling it within its file or function scope.

I think , although ridiculously repetitive, would do the work.

  • 👍 1 reaction

brummelte commented Sep 15, 2018 • edited Loading

The issue was, that that is not the perfect solution. But yes, that setting would work.

mweststrate commented Sep 17, 2018

Ok, to summarize:

rule makes perfect sense, I actually strongly recommend it, because assignments are really a no-op option though kinda defeats the purpose of immer, and should be kept to (the default), or an exception could be made by setting
  • 👍 16 reactions
  • 🎉 5 reactions
  • ❤️ 6 reactions
  • 🚀 3 reactions

@smably

jaimefps commented Jun 27, 2019

Just to make it quicker for ya'll,
if you are extending ,
just do the following in your file:

  • 👍 113 reactions
  • 🎉 18 reactions
  • ❤️ 18 reactions
  • 🚀 14 reactions

@nurbek-ab

nurbek-ab commented Nov 6, 2019

Also in case you have multiple producers in the same scope, like this:

This rule would work:

@lukemcgregor

SpotHimesh commented Oct 3, 2020

For people coming from future google searches, extending on above

To enable more semantic variable naming as well as avoiding problem in case of multiple producers in the same scope, we can do

.exports = { extends: [ 'airbnb', // this means you have "props" = "true" by default ], rules: { 'no-param-reassign': ['error', { props: true, ignorePropertyModificationsForRegex: ["^draft"] }], }, };

This should make it work for , ,

  • 👍 29 reactions
  • 😄 2 reactions
  • 🎉 3 reactions
  • ❤️ 5 reactions
  • 🚀 5 reactions

@zedelashvililevani

zedelashvililevani commented Nov 15, 2020

Another trick that works:

  • 👎 6 reactions
  • ❤️ 2 reactions

@yoshihiroxx

Crismon96 commented May 20, 2021 • edited Loading

So the rule in .eslintrc from you guys helped me to fix this problem in my immer code:

But if I want to reassign the state completely, like in this reducer (working with redux toolkit in this project):

Giving me the infamous linter warning

Do you guys know why it works with reassigning nested state but not the complete state or what I can do different?
I fallback to disabling the eslint rule for this line for now but I would rather not do that in this case.

@ljharb

ljharb commented May 20, 2021

in some JS engines, reassigning to a named argument heavily deoptimizes the function. Always make a new variable name instead.

  • 👀 1 reaction

@daliborfilus

daliborfilus commented May 14, 2022

That rule triggered for me in immer (that's how I landed on this issue), but also on code like this:

function groupBy(data, fnc) { return data.reduce((acc, curr) => { const res = fnc(curr); if (!acc[res]) acc[res] = [curr]; else acc[res].push(curr); return acc; }, {}); }

75:20 error Assignment to property of function parameter 'acc' no-param-reassign

So now I can't even use reduce anymore? This rule (with ) is just stupid.
I think I'll just set props to false.

@ssangervasi

No branches or pull requests

@ljharb

Disallow Reassignment of Function Parameters (no-param-reassign)

禁止对函数参数再赋值 (no-param-reassign).

Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

对函数参数中的变量进行赋值可能会误导读者,导致混乱,也会改变 arguments 对象。通常,对函数参数进行赋值并非有意为之,更多的是程序员的书写错误做成的。

This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

当函数参数被修改时,该规则也可能会失效。由此造成的副作用可能导致不直观的执行流程,使错误难以跟踪。

Rule Details

This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

该规则旨在避免出现对函数参数的修改或重新赋值造成的非自主行为。

Examples of incorrect code for this rule:

Examples of correct code for this rule:

This rule takes one option, an object, with a boolean property "props" and an array "ignorePropertyModificationsFor" . "props" is false by default. If "props" is set to true , this rule warns against the modification of parameter properties unless they’re included in "ignorePropertyModificationsFor" , which is an empty array by default.

该规则有一个选项,是个对象,其中有一个 "props" 的布尔属性和一个数组属性 "ignorePropertyModificationsFor" 。 "props" 默认为 false 。如果 "props" 设置为 true ,对参数的任何属性的修改,该规则都将发出警告, 除非在 "ignorePropertyModificationsFor" (默认为空数组) 有该参数。

Examples of correct code for the default { "props": false } option:

默认选项 { "props": false } 的 正确 代码示例:

Examples of incorrect code for the { "props": true } option:

选项 { "props": true } 的 错误 代码示例:

Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

选项 { "props": true } 并设置了 "ignorePropertyModificationsFor" 的 正确 代码示例:

When Not To Use It

If you want to allow assignment to function parameters, then you can safely disable this rule.

如果你想允许对函数参数重新赋值,你可以禁用此规则。

Further Reading

  • JavaScript: Don’t Reassign Your Function Arguments

This rule was introduced in ESLint 0.18.0.

该规则在 ESLint 0.18.0 中被引入。

  • Rule source
  • Documentation source
  • Docs »
  • The Linux kernel user’s and administrator’s guide »
  • The kernel’s command-line parameters
  • View page source

The kernel’s command-line parameters ¶

The following is a consolidated list of the kernel parameters as implemented by the __setup(), core_param() and module_param() macros and sorted into English Dictionary order (defined as ignoring all punctuation and sorting digits before letters in a case insensitive manner), and with descriptions where known.

The kernel parses parameters from the kernel command line up to “–”; if it doesn’t recognize a parameter and it doesn’t contain a ‘.’, the parameter gets passed to init: parameters with ‘=’ go into init’s environment, others are passed as command line arguments to init. Everything after “–” is passed as an argument to init.

Module parameters can be specified in two ways: via the kernel command line with a module name prefix, or via modprobe, e.g.:

Parameters for modules which are built into the kernel need to be specified on the kernel command line. modprobe looks through the kernel command line (/proc/cmdline) and collects module parameters when it loads a module, so the kernel command line can be used for loadable modules too.

Hyphens (dashes) and underscores are equivalent in parameter names, so:

can also be entered as:

Double-quotes can be used to protect spaces in values, e.g.:

cpu lists: ¶

Some kernel parameters take a list of CPUs as a value, e.g. isolcpus, nohz_full, irqaffinity, rcu_nocbs. The format of this list is:

<cpu number>,...,<cpu number>
<cpu number>-<cpu number> (must be a positive range in ascending order)

or a mixture

<cpu number>,...,<cpu number>-<cpu number>

Note that for the special case of a range one can split the range into equal sized groups and for each group use some amount from the beginning of that group:

<cpu number>-cpu number>:<used size>/<group size>

For example one can add to the command line following parameter:

isolcpus=1,2,10-20,100-2000:2/25

where the final item represents CPUs 100,101,125,126,150,151,...

This document may not be entirely up to date and comprehensive. The command “modinfo -p ${modulename}” shows a current list of all parameters of a loadable module. Loadable modules, after being loaded into the running kernel, also reveal their parameters in /sys/module/${modulename}/parameters/. Some of these parameters may be changed at runtime by the command echo -n ${value} > /sys/module/${modulename}/parameters/${parm} .

The parameters listed below are only valid if certain kernel build options were enabled and if respective hardware is present. The text in square brackets at the beginning of each description states the restrictions within which a parameter is applicable:

In addition, the following text indicates that the option:

Parameters denoted with BOOT are actually interpreted by the boot loader, and have no meaning to the kernel directly. Do not modify the syntax of boot loader parameters without extreme need or coordination with <Documentation/x86/boot.txt>.

There are also arch-specific kernel-parameters not documented here. See for example <Documentation/x86/x86_64/boot-options.txt>.

Note that ALL kernel parameters listed below are CASE SENSITIVE, and that a trailing = on the name of any parameter states that that parameter will be entered as an environment variable, whereas its absence indicates that it will appear as a kernel argument readable via /proc/cmdline by programs running once the system is up.

The number of kernel parameters is not limited, but the length of the complete command line (parameters including spaces etc.) is limited to a fixed number of characters. This limit depends on the architecture and is between 256 and 4096 characters. It is defined in the file ./include/asm/setup.h as COMMAND_LINE_SIZE.

Finally, the [KMG] suffix is commonly described after a number of kernel parameter values. These ‘K’, ‘M’, and ‘G’ letters represent the _binary_ multipliers ‘Kilo’, ‘Mega’, and ‘Giga’, equaling 2^10, 2^20, and 2^30 bytes respectively. Such letter suffixes can also be entirely omitted:

Add more DRM drivers.
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Assignment to function parameter 'value' no-param-reassign

I am trying to get rid off the no-param-reassign error from the following code.

Tried with adding the followings:

Nothing has worked. Also tried creating a new variable and assign to it. Still didn't work. I can't commit code due to that error.

I need to update this ( properties.color ) array element with function parameter value.

  • typescript-eslint

PineCone's user avatar

  • See if it helps, stackoverflow.com/a/35637900/13262332 –  DJ Hemath Commented Mar 25, 2022 at 4:20
  • Unfortunately I tried most of the suggestion from the post you suggested. But nothing worked. –  PineCone Commented Apr 4, 2022 at 7:55

Know someone who can answer? Share a link to this question via email , Twitter , or Facebook .

Your answer.

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Browse other questions tagged reactjs typescript-eslint reassign or ask your own question .

  • The Overflow Blog
  • Mobile Observability: monitoring performance through cracked screens, old...
  • Featured on Meta
  • Announcing a change to the data-dump process
  • Bringing clarity to status tag usage on meta sites
  • What does a new user need in a homepage experience on Stack Overflow?
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • Is it a date format of YYMMDD, MMDDYY, and/or DDMMYY?
  • World Building Knowledgebase - How to write good Military World Building
  • Does a held action have to be an action?
  • A SF novel where one character makes a "light portrait" of another one, with huge consequences
  • What happens to entropy during compression?
  • Does measuring a quantum object collapse the wave function even if the particle is not found in the position where it was measured?
  • decode the pipe
  • What is this device in my ceiling making out of battery chirps?
  • Is it valid to replace the limit of a function inside the indifnite integration when computing limits?
  • Whats the safest way to store a password in database?
  • Why is the !? annotation so rare?
  • Doesn't counting hole and electron current lead to double-counting of actual current?
  • When a star becomes a black hole do the neutrons that are squeezed together release binding energy and if so does this energy escape from the hole?
  • Do eternal ordinances such as the festival of unleavened bread pose a biblical contradiction?
  • Aligning text, image and list vertically in beamer slide
  • Should you refactor when there are no tests?
  • Can taut membranes and strings that are clamped at both ends propagate non-standing waves?
  • When to use negative binomial and Poisson regression
  • Why is simpler prose more popular these days?
  • Soldering RG179 coaxial cable directly to PCB
  • Create random points using minimum distance calculated on the fly using ModelBuilder in ArcGIS Pro
  • How do I define the solution to an inequality?
  • How can I Align an existing Object to the 3D Viewport's XY Plane?
  • What does ציר"ו stand for?

error assignment to property of function parameter no param reassign

IMAGES

  1. Assignment to property of function parameter no-param-reassign

    error assignment to property of function parameter no param reassign

  2. 解决Vue、vuex报“Assignment to property of function parameter ‘state‘” 的方法

    error assignment to property of function parameter no param reassign

  3. Assignment to property of function parameter no-param-reassign

    error assignment to property of function parameter no param reassign

  4. Assignment to property of function parameter 'XXX' no-param-reassign 记录

    error assignment to property of function parameter no param reassign

  5. Assignment to property of function parameter no-param-reassign

    error assignment to property of function parameter no param reassign

  6. Assignment to property of function parameter 'XXX' no-param-reassign 记录

    error assignment to property of function parameter no param reassign

VIDEO

  1. How to use Contour Tool with Full Property Function in CorelDraw X-7,6,5,4,3 |Hindi/Urdu| # 19

  2. Use Destructuring Assignment to Pass an Object as a Function's Parameters (ES6) freeCodeCamp

  3. How to use the error function for some tough integral

  4. 07 Use the Rest Parameter with Function Parameters

  5. 14 Use Destructuring Assignment to Pass an Object as a Function's Parameters

  6. "Debugging Tutorial: How to Fix 'SyntaxError: can't assign to function call' "

COMMENTS

  1. javascript

    The no-param-reassign warning makes sense for common functions, but for a classic Array.forEach loop over an array which you intend to mutate it isn't to appropriate. However, to get around this, you can also use Array.map with a new object (if you are like me, dislike snoozing warnings with comments): someArray = someArray.map((_item) => {.

  2. Assignment to property of function parameter (no-param-reassign)

    This is a common ESLint issue that appears frequently on old codebase. You have modified the result variable which was passed as parameter. This behavior is prohibited by the rule. To resolve it, copy the argument to a temporary variable and work on it instead: export const fn = article => article.categoryValueDtoSet.reduce((res, item) => {.

  3. Assignment to property of function parameter no-param-reassign

    A step-by-step guide on how to resolve the ESLint error Assignment to property of function parameter 'X' eslint no-param-reassign.

  4. no-param-reassign

    When Not To Use It If you want to allow assignment to function parameters, then you can safely disable this rule. Strict mode code doesn't sync indices of the arguments object with each parameter binding. Therefore, this rule is not necessary to protect against arguments object mutation in ESM modules or other strict mode functions.

  5. Understanding ESLint's `no-param-reassign` Rule for Clearer Functions

    Understanding ESLint's `no-param-reassign` Rule for Clearer Functions When you define a function, you can specify variables that the function will receive as input. These are called parameters. The no-param-reassign rule discourages directly changing the value of these parameters within the function.

  6. no-param-reassign

    Rule Details This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters. Examples of incorrect code for this rule: /*eslint no-param-reassign: "error"*/ function foo(bar) { bar = 13; } function foo(bar) { bar++; } Examples of correct code for this rule:

  7. no-param-reassign

    Disallow Reassignment of Function Parameters (no-param-reassign) Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object.

  8. What the Heck is the deal with no-param-reassign

    What this means when it comes to functions is that when you pass a value into a function which you stored in a variable the function invocation will copy the reference address of your object into a parameter variable to be used by the function. If the value is an object or an array and you modify that parameter you will be modifying the callers variable.

  9. no-param-reassign

    no-param-reassign Disallows reassignment of function parameters. Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

  10. No-param-reassign

    Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

  11. Why eslint throws "Assignment to property of function parameter

    It will allow you to reassign object properties but not the argument reference itself. Or you can disable the rule on specific lines with // eslint-disable-line no-param-reassign

  12. Do we want to recommend the `no-param-reassign` eslint rule in the docs

    I just had this idea when another user tried to assign to the state function argument. There is actually an eslint rule for that: no-param-reassign I'd suggest we either add that rule as a recommendation somehwere in the docs or go even ...

  13. noParameterAssign

    Disallow reassigning function parameters. Assignment to a function parameters can be misleading and confusing, as modifying parameters will also mutate the arguments object.

  14. Why assignment to property of function parameter is bad style

    jbruni commented on Nov 7, 2017 no-param-reassign as "never reassign parameters" is ok. no-param-reassign as "never mutate parameters" means eslint-config-airbnb enforces immutability paradigm. It makes a profound design choice for us.

  15. Arrow function should not return assignment. eslint no-return-assign

    To solve the error, wrap the assignment in curly braces, so it doesn't get returned from the arrow function. Arrow function should not return assignment. eslint no-return-assign

  16. no-param-reassign

    插件化、可配置的 JavaScript 代码检查工具,让你轻松地提高代码质量。

  17. Usage with eslint no-param-reassign #189

    I don't want to disable the eslint rule "no-param-reassign" globally, because it prevents errors. So this seems to be the best way to use immer with that rule enabled: const nextState = produce(bas...

  18. no-param-reassign

    This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters. 该规则旨在避免出现对函数参数的修改或重新赋值造成的非自主行为。. 错误 代码示例:. 正确 代码示例:. This rule takes one option, an object, with a boolean property and an array is by default. If ...

  19. TypeScript and redux tool kit , createSlice: Assignment to property of

    Hello I have a problem in my estlint: Assignment to property of function parameter 'state'. eslintno-param-reassign on this code: state.sideisOpen = action.payload; interface SideBar {

  20. The kernel's command-line parameters

    The kernel parses parameters from the kernel command line up to "-"; if it doesn't recognize a parameter and it doesn't contain a '.', the parameter gets passed to init: parameters with '=' go into init's environment, others are passed as command line arguments to init. Everything after "-" is passed as an argument to ...

  21. Assignment to function parameter 'value' no-param-reassign

    0 I am trying to get rid off the no-param-reassign error from the following code.