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.

Possible new rule-disallow naming a variable in a function the same as a function parameter

See original GitHub issue

I’d like to have a rule against naming variables in a function the same as a function parameter. It makes code unreadable, because it requires the reader to resolve the scope of current variable based on scoping rules and that’s not always easy, especially with let. I don’t think there is an eslint rule for this, but if there would be a a positive stance toward this rule by standard maintainers I’d love to write such a rule.

example of invalid code:

function (a) {
  let a
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ferosscommented, Oct 28, 2020

It seems like the no-redeclare rule has gotten stricter because this example is caught by the latest standard v15:

function test (a) {
  if (a) {
    var a = 1
    console.log(a)
  }
}

Closing this issue.

1reaction
capajcommented, May 19, 2017

@dcousens sorry, what I meant was:

function (a) {
  if (a) {
    let a = 1
    console.log(a)
  }
}

this one is valid currently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c++ - Is it valid for function parameter's names to be the same ...
Yes. Those variables are in different scopes, therefore it is perfectly valid. See Name lookup and Scope: Each name that appears in a...
Read more >
How to Better Name Your Functions and Variables | The Startup
When naming a function, variable or class, you should keep the following things in mind: Choose a word with meaning (provide some context);...
Read more >
Functions - JavaScript - MDN Web Docs
There are three ways for a function to refer to itself: The function's name; arguments.callee; An in-scope variable that refers to the function....
Read more >
Functions - Advanced R. - Hadley Wickham
Function arguments in R can have default values. Default arguments can even be defined in terms of variables created within the function. This...
Read more >
Working with arguments and variables in functions
As a result, any changes to these arguments in the function also change ... same variable name in the function argument and return...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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