How to have "Reformat Code" feature behave exactly like Prettier?
I do love Prettier and always set up a .prettierrc file for my projects. However, I find WebStorm "Reformat Code" to be much faster than the Prettier JavaScript package so, although I still want to keep Prettier support, I'd also like to use the "Reformat Code" command to enforce .prettierrc rules for speed.
The problem is that no matter how much I tweak code style rules, I can never have a 100% match between Prettier and "Reformat Code" results, which prevents me from using "Reformat Code" command altogether. And then I would have to tweak each project accordingly.
Is there a way for WebStorm to pick up from the .prettierrc file and apply exactly that same code style through "Reformat Code" command automatically?
请先登录再写评论。
WebStorm normally prompts you to import code style preferences from Prettier:
But, please, note that applying code style settings won't cause the IDE's 'Reformat Code' to match Prettier's code style exactly. Prettier is an opinionated formatter without a spec, with stylistic changes introduced in patch releases.
We import code style settings to the IDE to configure basic features like indent size to be used on Enter.
If you want the formatting to match exactly, use the 'Reformat With Prettier' action (described in a blog post)
That makes sense. Thanks!
Any way we can re-trigger that "Use code style..." prompt in an already existing project? I share the exact same sentiments as the original poster and would like to strive for sameness - the IntelliJ reformat code is so much faster.
Thanks Elena!
Background: I like to check on that "Reformat Code" option before I Git-commit files via the IntelliJ IDE. I assume this runs the Reformat Code action (and not the Reformat Using Prettier action). This, coupled with the fact Reformat Code runs faster, is why I'd like to push the Reformat Code frontier if it's at all possible.
You can re-import settings at any time using Apply Prettier Code Style Rules in the .prettierrc right-click menu:
Excellent! Thanks Elena!