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

Fix: extend prefer-const fixer range to whole declaration (fixes #13899) #14033

Merged
merged 2 commits into from Jan 30, 2021

Conversation

@snitin315
Copy link
Contributor

@snitin315 snitin315 commented Jan 24, 2021

Prerequisites checklist

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

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

What changes did you make? (Give an overview)

Fixes #13899

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

@snitin315
Copy link
Contributor Author

@snitin315 snitin315 commented Jan 24, 2021

I'm not sure why the test case is failing although it is correctly converting
let someFunc = () => { let a = 1, b = 2; foo(a, b) } to const someFunc = () => { const a = 1, b = 2; foo(a, b) }
when I am testing manually.

eslint-prefer-const.mp4

@snitin315 snitin315 force-pushed the snitin315:fix/prefer-const branch from 38dfa5d to ae87625 Jan 24, 2021
@mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Jan 25, 2021

I'm not sure why the test case is failing

There are overlapping ranges now, so the fixes cannot be applied in the same pass.

RuleTester runs only one pass, which in this case fixes the outer let only:

const someFunc = () => { let a = 1, b = 2; foo(a, b) }

and compares the result of that single pass with the provided output.

Before this change, the ranges were not overlapping, so both lets could be fixed in the same pass.

although it is correctly converting
let someFunc = () => { let a = 1, b = 2; foo(a, b) } to const someFunc = () => { const a = 1, b = 2; foo(a, b) }
when I am testing manually.

--fix repeats linting up to 10 times if the code was auto-fixed, so the inner let gets fixed in the second pass.

@mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Jan 25, 2021

The solution is to change the output in the failing test case, to:

    output: "const someFunc = () => { let a = 1, b = 2; foo(a, b) }"

and it would be nice to also leave a comment that the inner let will be auto-fixed in the second pass.

@snitin315 snitin315 force-pushed the snitin315:fix/prefer-const branch from b4f7f00 to a22375b Jan 25, 2021
@snitin315
Copy link
Contributor Author

@snitin315 snitin315 commented Jan 25, 2021

There are overlapping ranges now, so the fixes cannot be applied in the same pass.

Thanks for the explanation @mdjermanovic.

The solution is to change the output in the failing test case, to:

I have updated the test case 🚀

Copy link
Member

@mdjermanovic mdjermanovic left a comment

LGTM, thanks!

@mdjermanovic mdjermanovic changed the title Fix: extend fixer range of prefer const to whole declaration Fix: extend fixer range of prefer-const to whole declaration Jan 25, 2021
@mdjermanovic mdjermanovic changed the title Fix: extend fixer range of prefer-const to whole declaration Fix: extend prefer-const fixer range to whole declaration (fixes #13899) Jan 30, 2021
@mdjermanovic mdjermanovic merged commit fb27422 into eslint:master Jan 30, 2021
13 checks passed
13 checks passed
@github-actions
Verify Files
Details
@github-actions
Test (ubuntu-latest, 15.x)
Details
@github-actions
Test (ubuntu-latest, 14.x)
Details
@github-actions
Test (ubuntu-latest, 13.x)
Details
@github-actions
Test (ubuntu-latest, 12.x)
Details
@github-actions
Test (ubuntu-latest, 10.x)
Details
@github-actions
Test (ubuntu-latest, 10.12.0)
Details
@github-actions
Test (windows-latest, 12.x)
Details
@github-actions
Test (macOS-latest, 12.x)
Details
@github-actions
Browser Test
Details
@eslint-deprecated
commit-message PR title follows commit message guidelines
Details
licence/cla Contributor License Agreement is signed.
Details
@eslint-deprecated
release-monitor No patch release is pending
Details
@mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Jan 30, 2021

Thanks for contributing!

@snitin315 snitin315 deleted the snitin315:fix/prefer-const branch Jan 30, 2021
@snitin315
Copy link
Contributor Author

@snitin315 snitin315 commented Jan 30, 2021

@mdjermanovic Thanks for your review and help. Can you point me towards some more beginner-friendly issues where I can help?

This was referenced Mar 10, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants