question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ignore parameter assignments to specific variables with no-param-reassign enabled

See original GitHub issue

What version of ESLint are you using? 2.11.1

With angular you often see patterns like

app.controller('MyCtrl', function($scope) {
  $scope.something = true;
});

It would be nice to be able to setup eslint to strictly lint everything but ignore assignments to $scope (if configured to ignore $scope)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:16
  • Comments:44 (24 by maintainers)

github_iconTop GitHub Comments

4reactions
platinumazurecommented, Dec 16, 2016

Okay, this needs a champion and I’ll step up.

4reactions
TobiasBalescommented, Jun 26, 2016

My proposed changes are: Add an optional array to the configuration of no-param-reassigned called ignorePropertiesFor It contains strings naming variables for which property assignments/modifications will be not be flagged as an error.

The configuration would look like:

{
  "rules": {
    "no-param-reassign": ["error", { "ignorePropertiesFor": ["angular", "res"] } ]
  }
}

With that configuration the following code would not produce errors:

app.controller('MyCtrl', function($scope) {
  $scope.something = true;
});

function someController(req, res, next) {
    res.statusCode = 404;
}

but this would report the usual property assignment errors:

function someFunction(randomParameter) {
  randomParameter.valid = false;
}

If one would just use ["error", { "proprs": false }] as configuration the last example and similar things would not be caught which is why I would like to propose that change and also implemented it already.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid no-param-reassign when setting a property ...
If you assign to a parameter and then try and access some of the parameters via the arguments object, it can lead to...
Read more >
no-param-reassign - ESLint - Pluggable JavaScript Linter
Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate ...
Read more >
Remove Assignments to Parameters
Problem: Some value is assigned to a parameter inside method's body. Solution: Use a local variable instead of a parameter.
Read more >
Writing Reducers with Immer | Redux Toolkit - JS.ORG
One of the primary rules of Redux is that our reducers are never allowed to ... ESLint rule to ignore mutations and assignment...
Read more >
List of available rules - ESLint - Pluggable JavaScript linter
disallow assignment operators in conditional expressions ... disallow catch clause parameters from shadowing variables in the outer scope.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found