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:

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

ESLint is a popular tool for JavaScript developers that helps enforce coding style and identify potential errors. It does this by following a set of rules that you can configure for your project

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

Here's how it works:The rule scans your code for variable declarations (like let, const, or var).Then it checks if the variable is ever used throughout the code

What it catches: The rule flags any instance where you reference a variable, function, or class before it's formally declared with const

Simply re-throwing the error: If your catch block just catches an error and then throws it again without any modification or handling

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

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

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

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

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
  • 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

优雅解决: assignment to property of function parameter ‘state‘

assignment to property of function parameter 'state' eslint no param reassign

在airbnb的eslint规则中,有这样一条规则 no-param-reassign

目的是提醒你不要直接修改函数的入参。因为假如入参是一个对象,修改入参可能会导致对象的属性被覆盖。

但有一些情况下,我们必须要这样做,比如在 vuex 中

其实,不仅仅是vuex,再比如express的 req res ,前端事件处理的 e.returnvalue 都需要直接给入参赋值。这时候我们显然不希望直接disable掉这条规则,或者在发生冲突的代码处单独disable。

这时候可以使用 ignorePropertyModificationsFor 这个属性,他可以为这个规则添加一个白名单,即指定的入参名称不予限制。看代码就明白了:

如上代码配置即可避免vuex与eslint的冲突。

assignment to property of function parameter 'state' eslint no param reassign

请填写红包祝福语或标题

assignment to property of function parameter 'state' eslint no param reassign

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。 2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

assignment to property of function parameter 'state' eslint no param reassign

The Linux Kernel

Quick search.

  • Development process
  • Submitting patches
  • Code of conduct
  • Maintainer handbook
  • All development-process docs
  • Driver APIs
  • Licensing rules
  • Writing documentation
  • Development tools
  • Testing guide
  • Hacking guide
  • Fault injection
  • Livepatching
  • Linux kernel release 6.x <http://kernel.org/>
  • Linux allocated devices (4.x+ version)
  • Documentation for /proc/sys
  • Linux ABI description
  • Feature status on all architectures
  • Hardware vulnerabilities
  • Reporting issues
  • Reporting regressions
  • How to quickly build a trimmed Linux kernel
  • How to verify bugs and bisect regressions
  • Bug hunting
  • Bisecting a bug
  • Tainted kernels
  • Ramoops oops/panic logger
  • Dynamic debug
  • Explaining the “No working init found.” boot hang message
  • Documentation for Kdump - The kexec-based Crash Dumping Solution
  • Performance monitor support
  • pstore block oops/panic logger
  • Rules on how to access information in sysfs
  • Discovering Linux kernel subsystems used by a workload
  • ACPI Support
  • ATA over Ethernet (AoE)
  • Auxiliary Display Support
  • A block layer cache (bcache)
  • The Android binderfs Filesystem
  • Kernel Support for miscellaneous Binary Formats (binfmt_misc)
  • Block Devices
  • Boot Configuration
  • Linux Braille Console
  • btmrvl driver
  • Control Groups version 1
  • Control Group v2
  • Clearing WARN_ONCE
  • How CPU topology info is exported via sysfs
  • Dell Remote BIOS Update driver (dell_rbu)
  • Device Mapper
  • The EFI Boot Stub
  • ext4 General Information
  • File system Monitoring with fanotify
  • Notes on the change from 16-bit UIDs to 32-bit UIDs
  • Hardware random number generators
  • Using the initial RAM disk (initrd)
  • I/O statistics fields
  • Java(tm) Binary Kernel Support for Linux v1.03
  • IBM’s Journaled File System (JFS) for Linux
  • Reducing OS jitter due to per-cpu kthreads
  • Laptop Drivers
  • Parallel port LCD/Keypad Panel support
  • LDM - Logical Disk Manager (Dynamic Disks)
  • Softlockup detector and hardlockup detector (aka nmi_watchdog)
  • Linux Security Module Usage
  • RAID arrays
  • Media subsystem admin and user guide
  • Memory Management
  • Kernel module signing facility
  • Mono(tm) Binary Kernel Support for Linux
  • Numa policy hit/miss statistics
  • Perf events and tool security
  • Power Management
  • Linux Plug and Play Documentation
  • RapidIO Subsystem Guide
  • Reliability, Availability and Serviceability (RAS)
  • Error decoding
  • Address translation
  • Real Time Clock (RTC) Drivers for Linux
  • Linux Serial Console
  • Video Mode Selection Support 2.13
  • Syscall User Dispatch
  • Linux Magic System Request Key Hacks
  • Thermal Subsystem
  • USB4 and Thunderbolt
  • Unicode support
  • Software cursor for VGA
  • Video Output Switcher Control
  • The SGI XFS Filesystem
  • Build system
  • Userspace tools
  • Userspace API
  • Firmware and Devicetree
  • CPU architectures
  • Unsorted documentation
  • Translations
  • Show Source

The kernel’s command-line parameters ¶

The following is a consolidated list of the kernel parameters as implemented by the __setup(), early_param(), 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,...

The value “N” can be used to represent the numerically last CPU on the system, i.e “foo_cpus=16-N” would be equivalent to “16-31” on a 32 core system.

Keep in mind that “N” is dynamic, so if system changes cause the bitmap width to change, such as less cores in the CPU list, then N and any ranges using N will also change. Use the same on a small 4 core system, and “16-N” becomes “16-3” and now the same boot input will be flagged as invalid (start > end).

The special case-tolerant group name “all” has a meaning of selecting all CPUs, so that “nohz_full=all” is the equivalent of “nohz_full=0-N”.

The semantics of “N” and “all” is supported on a level of bitmaps and holds for all users of bitmap_parselist().

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. This list should be kept in alphabetical order. 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 < The Linux/x86 Boot Protocol >.

There are also arch-specific kernel-parameters not documented here. See for example < AMD64 Specific Boot Options >.

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/uapi/asm-generic/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:

  • 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
  • The hidden cost of speed
  • The creator of Jenkins discusses CI/CD and balancing business with open source
  • 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

  • What's the benefit or drawback of being Small?
  • Hashable and ordered enums to describe states of a process
  • What`s this? (Found among circulating tumor cells)
  • How high does the ocean tide rise every 90 minutes due to the gravitational pull of the space station?
  • I'm not quite sure I understand this daily puzzle on Lichess (9/6/24)
  • Why is this bolt's thread the way it is?
  • Confusion about time dilation
  • Is it helpful to use a thicker gauge wire for only part of a long circuit run that could have higher loads?
  • Are incomplete magic squares with some integral entries necessarily purely integral
  • PCA to help select variables?
  • How should I tell my manager that he could delay my retirement with a raise?
  • What is the first work of fiction to feature a vampire-human hybrid or dhampir vampire hunter as a protagonist?
  • Can reinforcement learning rewards be a combination of current and new state?
  • No displayport over USBC with lenovo ideapad gaming 3 (15IHU6)
  • How to sum with respect to partitions
  • Manhattan distance
  • Why isn't a confidence level of anything >50% "good enough"?
  • SOT 23-6 SMD marking code GC1MGR
  • How should αἱμάτων in John 1:13 be interpreted: “not of blood” or “not of bloods”?
  • When has the SR-71 been used for civilian purposes?
  • What was Jesus' issue with Mary touching him after he'd returned to earth after His resurrection?
  • Nausea during high altitude cycling climbs
  • DateTime.ParseExact returns today if date string and format are set to "General"
  • Should Euler be credited with Prime Number Theorem?

assignment to property of function parameter 'state' eslint no param reassign

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

Option to disable no-param-reassign per function scope #8907

@dandv

dandv commented Jul 9, 2017 • edited Loading

If the function body code modifies a parameter that's passed by value (Number, String, Boolean, Date), eslint should not warn that the parameter is modified, since the modifications won't survive after the function returns.

(contrived) example:

timestamp2unix(timestamp) { if (!timestamp) timestamp = Date.now(); // <-- // another legitimate parameter reassignment if (timestamp < MIN_DATE_IN_HISTORY) timestamp = MIN_DATE_IN_HISTORY;assignment return new Date(timestamp).getTime(); }

@eslintbot

eslintbot commented Jul 9, 2017 • edited by platinumazure Loading

Hi , thanks for the issue. It looks like there's not enough information for us to know how to help you.

Requesting a new rule? Please see for instructions.

Sorry, something went wrong.

@platinumazure

dandv commented Jul 10, 2017 • edited Loading

: What I would like to do is disable for parameters passed by value. Something like

: [ 'warn', { 'allowPassedByValue': true }, ],

If ESLint can't infer the parameter passing type (e.g. from the adjacent JSDoc), then a function-level comment like this would solve the problem:

@ilyavolodin

ilyavolodin commented Jul 14, 2017

ESLint can't determine if the argument was passed by value, you need type system for that. (JSDoc is unreliable, since not everyone uses it, and it can be outdated). As to inline comment, you can already do that by adding

next to the assignment. Or by wrapping function into comments.

dandv commented Jul 14, 2017

Thanks . I meant a function-level comment like to disable the check for the entire function (or block) that line was found in.

Anyway, compared to your solution, my proposal would only save one line of comments, so probably the current way to wrap the function between and is good enough.

@not-an-aardvark

not-an-aardvark commented Aug 10, 2017

Closing because the existing solution is satisfactory.

@not-an-aardvark

No branches or pull requests

@dandv

IMAGES

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

    assignment to property of function parameter 'state' eslint no param reassign

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

    assignment to property of function parameter 'state' eslint no param reassign

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

    assignment to property of function parameter 'state' eslint no param reassign

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

    assignment to property of function parameter 'state' eslint no param reassign

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

    assignment to property of function parameter 'state' eslint no param reassign

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

    assignment to property of function parameter 'state' eslint 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. How to use Blend Tool with Complete Property Function in CorelDraw X-7,6,5,4,3 |Hindi/Urdu| # 20

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

  4. How to use All Line Connector Tools with Full Property Function in CorelDraw X-7,6,5,4,3 |Hindi| #17

  5. Solución BUG font-awesome: Type 'string' is not assignable to type 'IconProp' with Typescript

  6. Create an Eslint plugin

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

    function createEmployee(emp) { // ⛔️ Assignment to property of function parameter 'emp'. eslint no-param-reassign. emp.name = 'bobby hadz'; emp.salary = 500; return emp; } The ESLint rule forbids assignment to function parameters because modifying a function's parameters also mutates the arguments object and can lead to confusing behavior.

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

    10. 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) => {.

  4. no-param-reassign

    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. Version

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

    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 ...

  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++; } function foo(bar) { for (bar in baz) {} } function foo(bar) { for (bar of baz) {} }

  7. no-param-reassign

    A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.

  8. 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++;

  9. Do we want to recommend the no-param-reassign eslint rule in ...

    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 one step farther and create a shareable config package .. That way we could add some more recommended rules in the future.

  10. 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 ... /*eslint no-param-reassign: "error"*/ function foo ... with a boolean property "props" and an array "ignorePropertyModificationsFor". "props" is false by default. If "props" is set ...

  11. TypeScript Reactjs: Assignment to property of function parameter 'state

    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 { sideisOpen: boolean; } const INITIAL_STATE: SideBar ...

  12. Usage with eslint no-param-reassign · Issue #189

    This rule (with props: true) is just stupid. I think I'll just set props to false. 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 (baseState, (draftState) => { /* eslint-disa...

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

    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;

  14. no-param-reassign error is set for @reduxjs/toolkit createSlice

    You can only write "mutating" logic in Redux Toolkit's createSlice and createReducer because they use Immer inside! If you write mutating logic in reducers without Immer, it will mutate the state and cause bugs! Is it possible to change eslint config for no-param-reassign rule to ignore the any code within createSlice or createReducer only?

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

    #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.

  16. 优雅解决: assignment to property of function parameter 'state'

    文章浏览阅读3w次,点赞7次,收藏5次。在airbnb的eslint规则中,有这样一条规则no-param-reassign目的是提醒你不要直接修改函数的入参。因为假如入参是一个对象,修改入参可能会导致对象的属性被覆盖。// 不好的做法function f1(obj) { obj.key = 1; // 可能对象本身就用key的属性,这样会覆盖原有的属性。

  17. Rule Change: Add option to no-param-reassign to allow ...

    I know that there is an option called ignorePropertyModificationsFor which allows properties of params with certain names to be modified, but this request is different. I'm requesting an option which would allow the param itself to be reassigned if it has a certain name. This would be useful for people who want to avoid param reassignment, but who want to allow it when using something like ...

  18. The kernel's command-line parameters

    The kernel's command-line parameters¶. The following is a consolidated list of the kernel parameters as implemented by the __setup(), early_param(), 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.

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

    Assignment to property of function parameter 'a' Eslint. ... Assignment to property of function parameter (no-param-reassign) 2 ... Argument expression expected. eslint" with Typescript map function in React. 0 Fixing no-param-reassign Eslint issue in function. 6 ...

  20. Option to disable no-param-reassign per function scope #8907

    Thanks @ilyavolodin.I meant a function-level comment like // eslint-disable-func no-param-reassign to disable the check for the entire function (or block) that line was found in.. Anyway, compared to your solution, my proposal would only save one line of comments, so probably the current way to wrap the function between /* eslint-disable no-param-reassign */ and /* eslint-enable */ is good enough.