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(cli): pass in parser to prettier format to avoid deprecation warning #662

Merged
merged 2 commits into from
Jan 10, 2022

Conversation

mikaelbr
Copy link
Contributor

@mikaelbr mikaelbr commented Jan 6, 2022

Summary

Prettier now gives warning when not being able to infer correct parser for files. It can infer by checking filepath or when explicitly setting parser. See issue and comment: prettier/prettier#4763 (comment)

This causes outputs such as:

Screenshot 2022-01-06 at 11 07 37

There are different ways to solve this:

  1. Pass in filename and let parser be inferred in format.
  2. Fetch inferred parser and pass in explicit parser to format.

In this PR I've chosen the latter option as it feels more explicit. In plugin-prettier it is hardcoded to babel but as I see it that might not be correct here?

Test plan

Tested by running and verifying that prettier deprecation warning is gone.

@vercel
Copy link

vercel bot commented Jan 6, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/gregberge/svgr/C9HyWFMP1e57K2tVNPM9rMfc1Nxt
✅ Preview: https://svgr-git-fork-mikaelbr-explicit-parser-prettie-fb4fc8-gregberge.vercel.app

Comment on lines 100 to 103
const prettierRcConfig = opts.runtimeConfig
? await resolveConfig(filepath, { editorconfig: true })
: {}
const prettierFileInfo = await getFileInfo(filepath)
Copy link
Owner

Choose a reason for hiding this comment

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

Need to be in a Promise.all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did some more digging in the prettier source code. getFileInfo ends up using resolveConfig again and inferring based on filepath. So to avoid extra work (and extra IO) it's better to just pass in file path as an option. Updated the code and verified by running the CLI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants