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: --init crash on question to upgrade/downgrade ESLint (fixes #13978) #13995

Merged
merged 1 commit into from Jan 15, 2021

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Jan 8, 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:

fixes #13978

What changes did you make? (Give an overview)

Fixed the --init "upgrade/downgrade ESLint" prompt to get the expected answers object.

It used to crash because the argument passed into message() was state, not answers. Thus, localESLintVersion and requiredESLintVersionRange properties were undefined, and then semver.ltr(undefined, undefined) throws.

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

  • We don't have tests for enquirer prompts and the flow. I tried this fix with ESLint v7.10.0 and eslint-config-standard (which requires eslint ^7.12.1, so an upgrade is needed) and it seems to be working fine.
  • message() apparently gets state as the argument (not answers). The fix could have been to get answers property from the argument. However, I couldn't find this documented, so decided to use this.state.answers, like in the rest of the code.

@mdjermanovic mdjermanovic added bug cli accepted labels Jan 8, 2021
Copy link
Member

@btmills btmills left a comment

I couldn't find any documentation on passing a function to message either, but the other prompts provide plenty of precedent for pulling it from this.state like you've done here. LGTM.

@mdjermanovic mdjermanovic merged commit 179a910 into master Jan 15, 2021
13 checks passed
@mdjermanovic mdjermanovic deleted the issue13978 branch Jan 15, 2021
This was referenced Mar 5, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jul 15, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age label Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted archived due to age bug cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants