How to disable auto removing Kotlin unused variables?

已回答

Hi,

Whenever the formatter runs it automatically removes variables that are unused, the entire line. I use format on save with auto-save enabled, so this is very annoying behavior when it removes before I write code to use the variable. 

I am using IDEA 2025.1 Beta

0
Does it help by unchecking "Unused variable" under Kotlin from "File | Settings | Editor | Inspections"?
0

I noticed my local variables being erased before I got a chance to write the code to use them. I find it outrageous that an IDE would even consider touching my code without my express consent. It is likely illegal as it is destruction of my intellectual property. A lawyer is probably in order at this point and a class action lawsuit. 

I suspect they think that since a variable is not used, why not erase it for you. They thinkt his is helpful, but it just shows how little they understand about software development. Sure, it's only a variable name, but they clearly don't understand how long it takes to come up with a good name. It is one of the, if not the, most difficult things a programmer has to do. 

Seriously, terrible. 

0

Hi all, regarding the issue, I think we may have two options to try:

1. Settings | Tools | Actions on Save, make sure “Run code cleanup” is disabled.
2. If you want to keep “Run code cleanup”, point its profile selector at a profile with Unused variable unchecked (Settings | Editor | Inspections | Kotlin | Redundant constructs)

0

Neither Settings | Editor | Inspections | Kotlin | Redundant constructs or Settings | Tools | Actions on Save work. Regardless, such a setting should never be on by default. Destroying code when clearly a warning would suffice is simply wrong. If someone wants this feature, make them turn it on. I'm just shaking my head in disbelief on this one. I did look up this and it is definitely illegal as I described. 
Jetbrains needs to talk to their legal department and quick. 

0

 Settings | Tools | Actions on Save | Run code cleanup is disabled by default. Which means when you save the project, code cleanup will not happen by default, and this is why we should check if this option is still disabled or not.

Bessermt Could you please double-check if  Settings | Tools | Actions on Save | Run code cleanup is still disabled in your IDE?

And if you have enabled third-party plugins, please disable them to exclude such behavior is caused by them: Settings | Plugins | ⚙ | Disable all downloaded plugins

0

请先登录再写评论。