简体   繁体   中英

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

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?

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:

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM