saveourtool/diktat

`WRONG_INDENTATION` rule behaving incorrectly with superclass constructor call arguments

Open

#1.404 geöffnet am 27. Juni 2022

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Kotlin (40 Forks)github user discovery
buggood first issueindentation

Repository-Metriken

Stars
 (571 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Both this

class Klass : Base("foo")

and this superclass constructor calls are indented correctly, in full accordance with 3.3. Indentation:

class Klass :
    Base("foo")

Now consider we want to split the superclass constructor call arguments into multiple lines:

class Klass : Base(
    "foo"
)

Even this is correct, too. Now, let's put a newline before the superclass call:

class Klass :
    Base(
        "foo"
    )

DiKTat will immediately complain:

Klass.kt:3:1: [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): expected 4 but was 8 (diktat-ruleset:indentation)
Klass.kt:4:1: [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): expected 0 but was 4 (diktat-ruleset:indentation)

So apparently DiKTat expects the following formatting (outright wrong):

class Klass :
    Base(
    "foo"
)

Steps to Reproduce

As it's obvious from the above example, two conditions must be met for the issue to manifest itself:

  1. The supertype constructor call should be put on a separate line.
  2. The supertype constructor call arguments should be put on individual lines.

There're more real-life examples which trigger this issue, e. g.:

class Klass :
    Base(
        "foo",
        ::Klass,
        listOf(
            "foo",
            "bar",
            "baz"
        )
    ),
    Cloneable,
    CharSequence {
    // ...
}

or even

class IndentationRuleFixTest :
    FixTestBase(
        "test/paragraph3/indentation",
        ::IndentationRule,
        listOf(
            RulesConfig(WRONG_INDENTATION.name, true,
                mapOf(
                    "newlineAtEnd" to "true",
                    "extendedIndentOfParameters" to "true",
                    "alignedParameters" to "true",
                    "extendedIndentAfterOperators" to "true",
                    "extendedIndentBeforeDot" to "true",
                )
            )
        )
    ),
    IndentationRuleTestMixin,
    IndentationRuleTestResources {
    // ...
}

Environment information

  • diktat version: 1.2.0
  • build tool (maven/gradle): Maven
  • how is diktat run (CLI, plugin, etc.): Maven plug-in
  • kotlin version: 1.7.0
  • operating system: Windows

Contributor Guide