nbadal / ktlint-intellij-plugin

Ktlint plugin for IntelliJ IDEA + Android Studio
MIT License
166 stars 24 forks source link

KtLint warning hide Idea suggestions for improve code #506

Closed mtrakal closed 6 months ago

mtrakal commented 6 months ago

With ktLint plugin disabled:

image

With ktLint plugin enabled (distract free mode):

image

It hides all Idea suggestions, so the code can't be autocorrected by suggestions and must be fixed manually.

mtrakal commented 6 months ago

Manual mode show proper suggestions... So maybe combining it some way together (don't show warnings/errors, but format code on Save as in Distract free mode) will be the perfect match :).

paul-dingemans commented 6 months ago

It hides all Idea suggestions, so the code can't be autocorrected by suggestions and must be fixed manually.

In distract-free mode only violations will be shown which can not be autocorrected. Violations that can be autocorrected are resolved on reformatting the code, and by default also whenever you save.

Manual mode show proper suggestions... So maybe combining it some way together (don't show warnings/errors, but format code on Save as in Distract free mode) will be the perfect match :).

Violations which can be autocorrected are not shown on purpose, as they distract the user and potentially can lead to manual fixes by the developer instead of letting Ktlint do so.

QuinnBast commented 6 months ago

I agree with this issue. Alt+Enter should still show auto-correct suggestions.

Violations which can be autocorrected are not shown on purpose, as they distract the user and potentially can lead to manual fixes by the developer instead of letting Ktlint do so.

Does it matter? As it stands, the highlighting indicates that there are errors, but when trying to "fix" them through the context menu, there are no "auto-fix" suggestions.

If you want the functionality to be "Distraction free", then:

In Distract free mode:

In Manual Mode:

Currently, even in Manual mode, the suggestions disappear and I cannot auto-fix linting issues at all using this plugin unless I use the distraction-free mode, which I would prefer not to use. I like using manual mode.

I also posted about this in #482 but this issue might be more relevant

paul-dingemans commented 6 months ago

If you want the functionality to be "Distraction free", then:

In Distract free mode:

Don't even show linting errors at all since they will just be automatically fixed on save

Only errors which can not be autocorrected are shown in distract free mode.

In Manual Mode:

Suggestions should be highlighted and able to be autofixed through IntelliJ Context menu suggestions Currently, even in Manual mode, the suggestions disappear and I cannot auto-fix linting issues at all using this plugin unless I use the distraction-free mode, which I would prefer not to use. I like using manual mode.

I also posted about this in https://github.com/nbadal/ktlint-intellij-plugin/issues/482 but this issue might be more relevant

Context menu with auto fix for violation will be added once it can be guarranteed that it will only fix the highlighted error instead of all errors in that file that can be autocorrected. See https://github.com/nbadal/ktlint-intellij-plugin/issues/492#issuecomment-2019962905.

oszust002 commented 6 months ago

+1 on this thread, plugin which previously showed flaws directly in the code and was able to fix the changes under Alt+Enter or during reformatting code, now becomes unusable, because it does not do any of these things. Also, if I'm using older ktlint in project than in plugin, rules can be completely different, it would be nice to have possibility to just choose version of rules of ktlint (no file change, just version of ktlint)

paul-dingemans commented 6 months ago

Also, if I'm using older ktlint in project than in plugin, rules can be completely different, it would be nice to have possibility to just choose version of rules of ktlint (no file change, just version of ktlint)

See https://github.com/nbadal/ktlint-intellij-plugin/pull/487. Support back until 0.50.0 is coming your way in next release.

paul-dingemans commented 6 months ago

@mtrakal The screenshots you have posted relate to a violation reported by rule compose:mutable-state-autoboxing. This rule is not maintained by the Ktlint project. So if this rule does not offer an 'autocorrect' possibility for this specific violation, then the plugin can not offer that to you. Please contact the mainer of the compose ruleset to check whether autocorrect is supported.

If you have example of ktlint rule which finds a violation which can be autocorrected and is displayed in distract free mode then please submit a screenshot and raw source code. But I am quite sure you will not find such an example. As said before, violations which can be autocorrected are not shown in distract free mode because they can be fixed by ktlint. Manual fixing of such errors would be a waste of time. Not displaying such violations aims to prevent this waste. So all remaining violations in distract free are by definition violations which can not be autocorrected by the rule that reports the violation. This should be reported to the maintainer of the rule, and not in this Ktlint Intellij Plugin which only provides the integration with ktlint.

paul-dingemans commented 6 months ago

Disabled mode:

Screenshot 2024-05-08 at 17 51 43

Manual mode:

Screenshot 2024-05-08 at 17 55 17

Distract free:

Screenshot 2024-05-08 at 17 53 41
paul-dingemans commented 6 months ago

Closing issue as it does not seem to be a problem caused by the plugin, but by rules not supporting autocorrect.