nbadal / ktlint-intellij-plugin

Ktlint plugin for IntelliJ IDEA + Android Studio
MIT License
157 stars 23 forks source link

False positive for standard:function-signature? #443

Closed roschlau closed 7 months ago

roschlau commented 8 months ago

I have this code in a Kotlin file:

enum class RestrictionState {
    UnderLimit,
    AtLimit,
    OverLimit,
    ;

    companion object {
        fun fromLimited(limit: Int?, value: Int?) = OverLimit
    }
}

And ktlint reports this error: image

Seems weird to me, since afaict from the docs, this rule should only trigger if the full function signature doesn't fit within the max-line-length rule (which is at the default 140 for us). I'd prefer not to break the signature into multiple lines here.

Is there anything I can do to get more info on why this rule is triggering here, and how to prevent it? Spotless with ktlint doesn't seem to complain about this file.

paul-dingemans commented 8 months ago

A lot of details are missing in your report, so I have to guess what is happening in your case.

What version of Ktlint is used by your spotless version? What version of the ktlint-intellij-plugin are you using?

One thing that you can try, is to set the ktlint_code_style property in .editorconfig' to valueintellij_idea`. Read more in ktlint documentation.

roschlau commented 8 months ago

I've tried spotless with ktlint version 1.1.1, and the ktlint intelliJ plugin is in version 0.20.0. If there's any more info that would help, let me know!

Yeah, setting the code style to intellij_idea fixes it, but as far as I understand it just disables that rule completely, right? I do agree with the rule in general (at least as documented) and would like to keep it enabled, if possible. It just seems that for some reason it's not correctly checked. Unless I'm mistaken about that!

paul-dingemans commented 7 months ago

Next thing that you can try, is to set code style explicitly to ktlint_official in .editorconfig. But, I am not sure whether Spotless does respect that.

The plugin is still on 1.1.0 but that could not explain this behavior.

roschlau commented 7 months ago

Okay, after a few more tests, now spotless also reports the same error. That's... Weird, not sure what was going on the first time. Then I guess my question is why the rule is triggering, since I don't believe it should, but that then has nothing to do with the IntelliJ plugin, so I'll close this issue here. Thanks for the help, and sorry for bothering you with a non-issue!

Edit: Now I found even that problem - I previously overlooked that the rule by default also triggers on exceeding a certain number of function parameters, even if the signature would fit the max line length. So turns out I was just being very dense here.