Skip to content
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 declaration loc to message in block-scoped-var #17252

Merged
merged 2 commits into from Jun 11, 2023
Merged

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Jun 7, 2023

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Fixes #17244

What changes did you make? (Give an overview)

In the block-scoped-var rule, I added the location info of declarations to reported messages. This should clarify cases where there are multiple errors on the same reference, and seems useful in general.

Is there anything you'd like reviewers to focus on?

@mdjermanovic mdjermanovic requested a review from a team as a code owner June 7, 2023 17:53
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Jun 7, 2023
@mdjermanovic mdjermanovic added rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Jun 7, 2023
@fasttime
Copy link
Member

fasttime commented Jun 7, 2023

Thanks for this PR! I would suggest to add a test with at least 3 redeclarations of a variable in different blocks, for example:

if (foo) {
    var a = 1;
} else if (bar) {
    var a = 2;
} else {
    var a = 3;
}

This would let us verify the case of two (or more) messages with the same line and column but different data.

In the current implementation, when $n \geq 1$ blocks in a scope declare the same variable, the rule will report $n\times(n - 1)$ problems. I think that this unexpectedly large number or messages (and the fact that they all contained the same text!) is the reason for the confusion in the linked issue #17244.

@mdjermanovic
Copy link
Member Author

mdjermanovic commented Jun 8, 2023

if (foo) {
    var a = 1;
} else if (bar) {
    var a = 2;
} else {
    var a = 3;
}

I added this test in e85f274, thanks for the suggestion!

Copy link
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Contributor

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Can we merge PRs or do we need to hold PRs until we finish #17225?

@mdjermanovic
Copy link
Member Author

Can we merge PRs or do we need to hold PRs until we finish #17225?

We can merge all PRs now, only it would be best to avoid merging those that could cause merge conflicts with tasks from #17225.

@mdjermanovic mdjermanovic merged commit e50fac3 into main Jun 11, 2023
17 checks passed
@mdjermanovic mdjermanovic deleted the issue17244 branch June 11, 2023 15:28
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Dec 9, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

block-scoped-var rule reports duplicate issues in some cases
3 participants