-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
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
no-shadow: allow a declaration's body to reuse the declared variable's name #12687
Comments
This makes sense to me. As far as I understand it, there's no danger here because it hasn't been declared yet and so cannot be overwritten. The following example leads to a let user = ['philipahlberg', 'kaicataldo'].find(p => user === 'philipahlberg');
|
There are similar patterns: // variable declarations
const a = [].find(a => true)
// assignment patterns in variable declarations or parameters
const [b = [].find(b => true)] = dummy
const { c = [].find(c => true) } = dummy
function func(d = [].find(d => true)) {}
// for-in / for-of with variable declarations
for (const e in [].find(e => true)) {}
for (const f of [].find(f => true)) {} Those |
It seems like it's sort of checked already, but perhaps it fails because the initialized variable is inserted into the outer scope before evaluating the rule or something similar? |
@philipahlberg That check is to avoid reporting function expression names: const a = function a() {} |
Any updates on this? |
I think this could be classified as a bug since the rule currently has false negatives. @mysticatea Thoughts? |
It seems to me like you generally agree that it should be implemented/fixed. Is that correct? In that case, I wouldn't mind looking into it myself, assuming you don't have time to do so. I'm not familiar with the ESLint codebase though, so any help with getting started would be appreciated. Perhaps you have a forum/discord/irc where I can ask, if anything comes up? |
Sorry for the radio silence on our end, and thanks for being willing to work on this! It looks like both @mysticatea and myself agree that this is a false-positive bug and I'm therefore going to mark it as accepted. We would gladly accept a PR for this! We have some documentation around contributing that can be found here. If you have any questions, feel free to comment here (or on a work in progress pull request, if that's easier), or stop by our Gitter chat. We're happy to help :) |
…4963) * Fix: Remove warning in initialized variables (fixes eslint#12687) * Fix: Remove warning in initialized variables (fixes eslint#12687) * Fix: Remove warning in initialized variables (fixes eslint#12687) * Docs: add invalid ambiguous example in doc (fixes eslint#12687) * Docs: add invalid ambiguous example in doc (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * Fix: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687) * feat: Adding option for variables on intialization (fixes eslint#12687)
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:
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 sideperson
.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.
The text was updated successfully, but these errors were encountered: