-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
feat: Add ignoreOnInitialization
option to no-shadow rule
#14963
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionally looks good. I just left some comments on how to clarify what is happening.
Hi @nzakas, thank you so much for reviewing the PR. |
The requested changes are addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just want to give others the chance to review too. Thanks!
Hi @mdjermanovic, thank you for the explanation. The requested changes are addressed. |
I'm not the maintainer but I was interested in this fix so I looked at your code. const a = fn(()=>{
class C {
fn () {
const a = 42
return a
}
}
return new C()
}) What do you think? |
@ota-meshi I think we should report the source code, I will update the pull request to include your example. |
@mdjermanovic can you check to see if your comments were addressed? |
Comments regarding the behavior of this rule with My other concern is that it isn't clearly defined what we want to fix (only parameters of functions that are arguments of function calls that are variable initializers should be excluded from shadowing that variable?), and why it should be fixed. The original example from #12687 is: const person = people.find(person => person.name === "John"); This is shadowing, because at the moment when the inner Problem is that the
Is this "shadowing before the outer variable is defined" or not? If we say that variable definition ends where the initializer ends, then it is "before", so My opinion is that isn't clear if #12687 is a bug or intended behavior, and that we should resolve it by adding a new option rather than changing the current behavior. |
@mdjermanovic , You are right, the rule is working as expected, the inner variable person is shadowing the outer variable person, but developers are confused by this example:
I think we should close the issue #12687 and this PR and add the ambiguous example in the documentation. For the code source mentioned by @ota-meshi the rule doesn't report it, we need to create a new issue and I will fix it. |
I'm not suggesting that we close #12687, but to consider adding an option for that behavior.
It works in the current version of this rule: /* eslint no-shadow: error */
const a = fn(()=>{
class C {
fn () {
const a = 42 // 'a' is already declared in the upper scope
return a
}
}
return new C()
}) |
@mdjermanovic The requested changes are addressed. |
Hi @mdjermanovic, thank you so much for your time reviewing the PR. The requested changes are addressed. |
ignoreOnInitialization
option to no-shadow rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@boutahlilsoufiane thanks for addressing all reviews! I think the most complex part of this change is now well done. I left some suggestions.
Hi @mdjermanovic, thanks a lot for your contributions, you played a big role in this. The comments are addressed. |
Hi @mdjermanovic, thanks a lot for your time and your efforts, thanks a lot for taking the time to explain things more clearly, I think the option |
Hi @mdjermanovic, thanks a lot for your time and your efforts. The comment is addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! I'll leave this open for a day in case someone else wants to review it before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work. Thanks for your patience and responsiveness.
@boutahlilsoufiane great work, thanks for contributing! |
Hi @nzakas and @mdjermanovic Thanks a lot for approving the changes. Thanks a lot, @mdjermanovic for your big help, this wasn't going to be merged without you. |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [eslint](https://eslint.org) ([source](https://github.com/eslint/eslint)) | devDependencies | minor | [`8.9.0` -> `8.10.0`](https://renovatebot.com/diffs/npm/eslint/8.9.0/8.10.0) | --- ### Release Notes <details> <summary>eslint/eslint</summary> ### [`v8.10.0`](https://github.com/eslint/eslint/releases/v8.10.0) [Compare Source](eslint/eslint@v8.9.0...v8.10.0) #### Features - [`6e2c325`](eslint/eslint@6e2c325) feat: Add `ignoreOnInitialization` option to no-shadow rule ([#​14963](eslint/eslint#14963)) (Soufiane Boutahlil) - [`115cae5`](eslint/eslint@115cae5) feat: `--debug` prints time it takes to parse a file ([#​15609](eslint/eslint#15609)) (Bartek Iwańczuk) - [`345e70d`](eslint/eslint@345e70d) feat: Add `onlyOneSimpleParam` option to no-confusing-arrow rule ([#​15566](eslint/eslint#15566)) (Gautam Arora) #### Bug Fixes - [`cdc5802`](eslint/eslint@cdc5802) fix: Avoid `__dirname` for built-in configs ([#​15616](eslint/eslint#15616)) (DoZerg) - [`ee7c5d1`](eslint/eslint@ee7c5d1) fix: false positive in `camelcase` with combined properties ([#​15581](eslint/eslint#15581)) (Nitin Kumar) #### Documentation - [`1005bd5`](eslint/eslint@1005bd5) docs: update CLA information ([#​15630](eslint/eslint#15630)) (Nitin Kumar) - [`5d65c3b`](eslint/eslint@5d65c3b) docs: Fix typo in `no-irregular-whitespace` ([#​15634](eslint/eslint#15634)) (Ryota Sekiya) - [`b93af98`](eslint/eslint@b93af98) docs: add links between rules about whitespace around block curly braces ([#​15625](eslint/eslint#15625)) (Milos Djermanovic) - [`ebc0460`](eslint/eslint@ebc0460) docs: update babel links ([#​15624](eslint/eslint#15624)) (Milos Djermanovic) #### Chores - [`7cec74e`](eslint/eslint@7cec74e) chore: upgrade [@​eslint/eslintrc](https://github.com/eslint/eslintrc)[@​1](https://github.com/1).2.0 ([#​15648](eslint/eslint#15648)) (Milos Djermanovic) - [`11c8580`](eslint/eslint@11c8580) chore: read `ESLINT_MOCHA_TIMEOUT` env var in Makefile.js ([#​15626](eslint/eslint#15626)) (Piggy) - [`bfaa548`](eslint/eslint@bfaa548) test: add integration tests with built-in configs ([#​15612](eslint/eslint#15612)) (Milos Djermanovic) - [`39a2fb3`](eslint/eslint@39a2fb3) perf: fix lazy loading of core rules ([#​15606](eslint/eslint#15606)) (Milos Djermanovic) - [`3fc9196`](eslint/eslint@3fc9196) chore: include `tests/conf` in test runs ([#​15610](eslint/eslint#15610)) (Milos Djermanovic) </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Co-authored-by: cabr2-bot <cabr2.help@gmail.com> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1190 Reviewed-by: 6543 <6543@noreply.codeberg.org> Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org> Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
…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)
…slint#14963)" This reverts commit 548818c.
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[X] Changes an existing rule
What changes did you make? (Give an overview)
Fix the issue here: #12687
Adding a new option
ignoreOnInitialization
to prevent reporting variables on initialization statements.This is an example:
Is there anything you'd like reviewers to focus on?
No.