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
Merged

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

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?

@eslint-deprecated eslint-deprecated bot added the triage label Jan 24, 2021
@snitin315
Copy link
Contributor Author

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

@mdjermanovic
Copy link
Member

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 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.

@mdjermanovic mdjermanovic added accepted autofix bug rule and removed triage labels Jan 25, 2021
@snitin315
Copy link
Contributor Author

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
@mdjermanovic
Copy link
Member

mdjermanovic commented Jan 30, 2021

Thanks for contributing!

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

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?

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jul 30, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age label Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted archived due to age autofix bug rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants