dubreuia/intellij-plugin-save-actions

Request: for "Reformat file" on save, please prevent it in case it changes logic or when the code has errors

Opened this issue · 10 comments

Describe the solution you'd like

Suppose I have these settings:

image

On Java and especially on Kotlin, when I leave the IDE in the background (pressing Home key, for example), it sometimes auto-formats when it shouldn't.

For example in this case of Kotlin, it's really annoying, as I haven't finished writing what's on the line with the "notificationManager." :

fun foo(context: Context, notification: Notification) {
    val notificationManager = NotificationManagerCompat.from(context)
    notificationManager.
    notificationManager.notify(123, notification)
}

It becomes this way:

fun foo(context: Context, notification: Notification) {
    val notificationManager = NotificationManagerCompat.from(context)
    notificationManager.notificationManager.notify(123, notification)
}

See video:

studio64_2023-05-10_12-21-25.zip

And sample:

My Application.zip

Please have some option to avoid it. Maybe even turn it on by default.

For what product
Intellij (Android Studio)

Turn off auto save in your IDE to prevent reformatting. This plugin is triggered on "save" if the first option is enabled. "Save" means "save" (also auto save).

But I want it to auto-save.

Disable first option and use short cuts (second option). That's how it works.

But I want this turned on too. That's one of the reasons I use this plugin...

See my first answer. If save is triggered, this plugin is doing its job. Feel free to fork it and try to modify it.
I am using the short cut option for many years without any issues.

I know it's doing its job. It does it well, but when I leave the IDE, I don't want it to do anything, because I'm not ready yet for formatting in case the code gets this way.
Sometimes I write something, and go to another window to check what I should write next, and then this happens.

So, my request is to prevent it from happening in such cases.

I know what you mean but it is triggered by save even if save is triggered in background every 15 sec..
The author of this plugin won't do anything anymore.

There were problems in the past when the plugin was run only in the active window, especially since files can be open in multiple windows at the same time.

Therefore only remains:

  • Choose other settings and press three buttons if needed (that's how I do it).
  • Modify the plugin according to your needs
  • Live with the Auto Save formatting

@fishermans Are you saying this plugin won't get updated anymore?
:(

@markiewb Sadly this setting ("No action if compile errors...") doesn't work for the case I've shown:

    notificationManager.
    notificationManager.notify(123, notification)

Perhaps it's related to the fact that it's Kotlin?

As @fishermans said, unfortunately this plugin has been abandoned and therefore is incompatible with new versions of the Jetbrains IDEs.

In alternative you can use this fork:

https://plugins.jetbrains.com/plugin/21538-save-actions-tool
https://github.com/wanghuan9/intellij-plugin-save-action-tool
But for more information check the thread: #427