nbadal / ktlint-intellij-plugin

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

Wrong line annotated with wrongly indented comment #381

Closed Vampire closed 8 months ago

Vampire commented 9 months ago

On 0.20.0-beta-4 with this code:

    private inline fun <reified T> ExtensionContainer.maybeCreate(name: String): T =
    // do not use findByType as then the name-check is missing
        // if something is found by name, the cast ensures it is of the correct type
        (findByName(name) as T?) ?: create(name)

The second comment line is highlighted as being wrongly indented with 4 instead of 8 spaces, though the line above is the culprit. Formatting with ktlint correctly fixes it:

image

paul-dingemans commented 9 months ago

I can not reproduce the problem. In your example the problem is highlighted as "warning" which is really unexpected because the beta version of the plugin shows everything as error.

For me the error is correctly highlighted. Screenshot 2023-12-02 at 18 05 53

Can you try with code sample below:

class ExtensionContainer

class Foo {
    private inline fun <reified T> ExtensionContainer.maybeCreate(name: String): T =
        // do not use findByType as then the name-check is missing
        // if something is found by name, the cast ensures it is of the correct type
        (findByName(name) as T?) ?: create(name)

    fun <T> create(name: String): T {
        TODO("Not yet implemented")
    }

    fun findByName(name: String): Any = 42
}

If the sample above still shows the same problem, then please provide your .editorconfig. The .editorconfig is used, was:

root = true

[*.{kt,kts}]
# ktlint_code_style = android_studio
# ktlint_code_style = ktlint_official
ktlint_code_style = intellij_idea
ktlint_standard=enabled
# ktlint_experimental=enabled
Vampire commented 9 months ago

In your example the problem is highlighted as "warning" which is really unexpected because the beta version of the plugin shows everything as error.

Only if the plugin is enabled. ;-) In that case it was "unconfigured" .

Can you try with code sample below:

Sure, as soon as #399 is resolved, because right now I don't get any findings displayed with beta-5

paul-dingemans commented 8 months ago

@Vampire I am assuming this is resolved in 0.20.0 version of the plugin. Please let me know when it is not resolved, so that I can reopen the issue.