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.

no-shadow: allow a declaration's body to reuse the declared variable's name

See original GitHub issue

What rule do you want to change? no-shadow

Does this change cause the rule to produce more or fewer warnings? Fewer warnings

How will the change be implemented? (New option, new default behavior, etc.)? New default behavior

Please provide some example code that this change will affect:

const person = people.find(person => person.name === "John");

What does the rule currently do for this code? It currently produces a warning, claiming that the right-hand side person shadows the left-hand side person.

What will the rule do after it’s changed? It will not produce warnings when the purportedly-shadowed variable has not been declared.

I believe the current behavior is incorrect, as the variable has not (semantically) been declared at the point where the warning is generated, and so it can not be shadowed.

Are you willing to submit a pull request to implement this change? Yes, though I would need some pointers on how to get started.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
boutahlilsoufianecommented, Aug 7, 2021

I’m going to do this.

1reaction
barklundcommented, May 18, 2020

The use-case coming up in google/web-stories-wp is:

const { a } = cacheStuff(({ a }) => ({ a });

This false negative from no-shadow is assumed to be fixed by this issue as well. If not, adding it here for consistency.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-shadow - ESLint - Pluggable JavaScript Linter
Disallow variable declarations from shadowing variables declared in the outer scope ... variable shares the same name as a variable in its containing...
Read more >
Variables in Standard ML change if a new function declaration ...
But SML does allow you to shadow variable bindings, meaning that you are allowed to reuse an existing variable name for a new...
Read more >
Blocks and Variable Scope
The scope of a variable is that set of code statements in which the ... programming practice is to reuse variable names in...
Read more >
c-decl.c - Apple Open Source
Process declarations and variables for C compiler. ... Declaration of parm before function body */ FIELD, /* Declaration inside struct or union */...
Read more >
DCL01-C. Do not reuse variable names in subscopes
A block should not declare a variable with the same name as a variable declared in any block that contains it. Reusing variable...
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