-
Notifications
You must be signed in to change notification settings - Fork 458
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
IDEA-180965: Add support for IntelliJ formatter #200
Comments
Happy to merge a PR for this, but currently nobody is working on it. You can use a custom step do this, there's an example of how to do this (and a description of its shortcomings) in #119. |
Commented interesting issue on the IntelliJ issue tracker related to this enhancement: |
Also: Provide standalone formatter or API https://youtrack.jetbrains.com/issue/IDEABKL-7685 |
If you don't care about using the IntelliJ formatter specifically, but rather just the IntelliJ IDE to autoformat in a way that agrees with Spotless, another path forward would be to make a plugin for IntelliJ that calls out to the spotless IDE hook. For example, here's a plugin for VSCode. |
It would be awesome if this come into reality! |
Long shot but, any news about it? |
If we want to use the intellij java code style with spotless. What's the recommended approach? https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml |
@sbilello Spotless doesn't support the IntelliJ formatter yet. The way to get Google-style Java formatting is to use this instruction: spotless {
java {
googleJavaFormat().reflowLongStrings()
}
} It uses google-java-format, which is a successor to the IntelliJ XML file you linked, so I recommend google-java-format over it. :) |
Hey! I've actually been working on this as this is something that affects my day-to-day workflow and have a very basic working version of a Spotless IntelliJ plugin working. Here is the code. I'm waiting on JetBrains to approve the plugin for publishing, so it isn't available on the Marketplace yet, but you can install it in your own IDE via Settings/Preferences > Plugins > ⚙️ > Install plugin from disk... using this zip. It currently only supports an action "Reformat Code with Spotless" which is found under the Code menu item, but am planning on adding format on save and possibly linting/contextual fixes soon. Feedback encouraged and welcome. |
Fantastic, thanks so much @ragurney! Looks like a great plugin, I will submit a PR momentarily to better advertise your plugin to Spotless users. If your goal is to use existing Spotless rules with IntelliJ, then this issue is now solved (I'll be using your plugin!). Some people want something different, which is to have an |
Got it, thanks so much @nedtwigg! Thank you for the explanation about the other issue here, that makes sense, and it's very exciting that the plugin might be helpful to other Spotless users! I'm hoping to add further functionality to it soon, and looking forward to any feedback or feature requests you might have after using it. |
Great plugin @ragurney! 👍 What do you think about adding support for Maven? Would it make sense to have a single Spotless IntelliJ plugin that supports both Gradle and Maven? |
Thanks @lutovich! I'm leaning towards it being better to have a separate plugin for Maven just for separation of concerns, but if there's a dependable way to tell if an IntelliJ project is using Maven or Gradle that could work too and would be more DRY. I'll do some sleuthing and see if that's a possibility. Regardless, I think a prerequisite for a maven plugin would be adding an IDE hook similar to the one available for Spotless Gradle. |
I was able to use File Watchers to run |
@melissachang similar to @ragurney's IntelliJ plugin, this helps to execute Spotless via IntelliJ – which is already great! However, the issue here is basically about loading the IntelliJ formatter into Spotless. For example: spotless {
java {
intellij('173').configFile('intellij-prefs.xml')
}
} |
Yeah sorry for going a bit off-topic. It took me a while to figure out how to run spotless-on-save (mentioned as a feature request in this above comment). Currently it's not possible with Intellij formatter. Just documenting a way to do it, in case people want spotless-on-save. |
Is there any particular reason that Spotless Maven lacks parity with Spotless Gradle regarding the IDE hook? Are there extra challenges unique to maven in adding such functionality? (I'm new to the Java ecosystem so apologies for my ignorance) |
Nope, we just got PR's from Gradle users, that's all. |
@ragurney @lutovich @tonjohn @nedtwigg |
Hello! Any updates on the issue? I found docs: Format files from the command line | IntelliJ IDEA Documentation. I use this API myself to format code using neovim: vim.keymap.set("n", "<leader>oC", ":!idea format -s ~/idea.xml -r %<CR>edit<CR>") I'd be glad to try to implement the feature if maintainers think it's possible. PS. I tested this on Linux & MacOS. There some caveats:
Anyway considering all above, I'd gave a try to the feature. I'd add this as experimental due to unstable API of the IDE. |
A PR for this would be very welcome. |
Thanks for your hint @nedtwigg I created the I saw your PR #672. Maybe I'm missing something but I don't have any good ideas on running IDEA in test on every machine (CI at least). I can come up with a solution but maybe the team has an appropriate solution for the problem. Contribution guide helped a lot, thanks! |
Amazing! Note the following:
In this way, the tests are always compiled, even though they aren't run. Of all these "special" tests, the only ones which get run on CI right now are the npm tests. It would be better if they all ran, but it would be worse if the steps didn't exist at all. The important thing is that if someone wants to develop the step further, they aren't starting from scratch - they have tests, they just need to setup their local machine to have foreign exe in question. |
As described here: diffplug#200 (comment)
Thanks for the advice! Really appreciate it! I've just opened a Draft PR. |
The line wrapping options that can be configured with IntelliJ seem to be a little bit more flexible than the one available in Eclipse (e.g. lambda-related preferences).
The closest thing I've found to format Java sources using an IntelliJ code style is its command line formatter. Although that still requires having the full binaries of IntelliJ (but I hope to be wrong!).
The text was updated successfully, but these errors were encountered: