Closed rlnt closed 8 months ago
Just a question. What's the difference between this and the official plugin right here? https://github.com/ragurney/spotless-intellij-gradle
Hello! This plugin supports maven build tool, multi-module projects and gives some additional settings.
One thing I am missing in both plugins is the ability to format on save without third-party tools like Save Actions or File Watchers.
Have you considered adding your plugin as formatter for the Actions on Save section?
That would make it perfect. We are trying to replace the standard IntelliJ formatter we currently use with spotless because you can easily use it inside CI/CD but without automatic formatting in the local IDE, this is not ideal.
There is an open pull request for this on the official plugin but it hasn't been touched in a while: https://github.com/ragurney/spotless-intellij-gradle/pull/33
In general, looks like it's real to do. We can call spotless tasks on save. Furthermore, quick search says we could also add commit check: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009637400-Adding-actions-to-before-commit-toolbar-window
And I think the option above is what you need in order to prevent dev's to push unformatted changes into the repo. Because of spotless is not a formatter, it's a tool that gives the ability to integrate various formatters. So we'll make calls to an external system, and it's important to understand it's not so fast as native tasks. Especially for maven.
Save action is called many times during developing, and each time the system will little hang while spotless is applying. Unlike, commit action is called once.
I would have done that with a pre-commit hook but I am explicitly looking for the save action. I pretty much disabled auto-save and do it manually so this wouldn't be a big issue but I understand the concerns. Just searching for a better alternative to the default IDEA formatter that is easy to use in the remote repository's actions as well as locally.
Maybe I don't fully understand your case. Could you explain the CI/CD flow you expect?
I delved deeper into the precommit check ability and, unfortunately, obtained disappointing results. Checkin handlers should execute their operations synchronously to maintain the order of checks. However, this is not possible for external Gradle tasks due to an issue I mentioned a few months ago: https://youtrack.jetbrains.com/issue/IDEA-327879/Executing-Gradle-task-in-ProgressExecutionMode.MODALSYNC-hangs-the-IDE
If we return to the discussion regarding the ability to format code with Spotless on save, a new concern arises: We can execute the 'apply' task either for a specific file or for the entire project. And what should the plugin do if you have 15 unsaved files? We recognize that dealing with 15 tasks is excessive. Currently, developer handles the situation on its own, depending on the necessity.
The proper way, as I see it, is to natively integrate Spotless into the IDE 🙂
@rlnt Hello again! The precommit check was implemented in PR https://github.com/lipiridi/spotless-applier/pull/13 due to the fix for the Gradle sync execution bug in the newer IntelliJ IDEA version.
I would have done that with a pre-commit hook but I am explicitly looking for the save action. I pretty much disabled auto-save and do it manually so this wouldn't be a big issue but I understand the concerns. Just searching for a better alternative to the default IDEA formatter that is easy to use in the remote repository's actions as well as locally.
@rlnt Hi again! The action on save was implemented in PR https://github.com/lipiridi/spotless-applier/pull/17, Hope you'll find it useful
Just a question. What's the difference between this and the official plugin right here? https://github.com/ragurney/spotless-intellij-gradle