Possible new rule-disallow naming a variable in a function the same as a function parameter
See original GitHub issueI’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:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems like the
no-redeclare
rule has gotten stricter because this example is caught by the latest standard v15:Closing this issue.
@dcousens sorry, what I meant was:
this one is valid currently.