Can Prettier rules be applied using IntelliJ IDEA code style rules instead of the Prettier plugin?
Asked Answered
C

1

5

I have a project that contains some TypeScript files which I would like to format using the Prettier format while editing in IntelliJ IDEA, so that my resulting code matches that of my colleagues. Ideally, I only want to reformat the portions of the file I'm updating, so that my commits can be focused on my actual changes.

For other projects in IntelliJ IDEA I would typically use the built in code formatting and code style rules to format my code. The built-in TypeScript rules do not match the Prettier rules, and it's unclear whether those rules are published anywhere in an IntelliJ format I could just import.

For this reason, I've investigated the Prettier IntelliJ IDEA plugin. However, using this plugin requires some overhead; most notably, it requires a Node.js installation.

Is there an easy way to just use the Prettier rules using the standard IntelliJ reformatting functionality?

Cereus answered 17/5, 2022 at 21:36 Comment(0)
G
6

IDEA can import some code style settings (indents and some others) when .prettierrc is present in the project even if the Prettier itself is not installed:

enter image description here

But unfortunately it's not possible for us to match Prettier behavior completely because it doesn't have a specification and introduces stylistic changes in patch releases. So in general matching Prettier behavior with the built-in formatter is something that most likely will not happen. It's expected that if someone is using Prettier, they will be either using the Reformat with Prettier action or set up Prettier to run on Reformat Code action (https://www.jetbrains.com/help/idea/prettier.html#ws_prettier_default_formatter).

Gilbertgilberta answered 18/5, 2022 at 10:46 Comment(2)
Why does your screenshot look like it was printed with a malfunctioning cartridge and has a coffee stain?Dayton
it's because of a background image applied:)Gilbertgilberta

© 2022 - 2024 — McMap. All rights reserved.