Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong parameter list wrapping #1119

Closed
vRallev opened this issue Mar 24, 2021 · 2 comments
Closed

Wrong parameter list wrapping #1119

vRallev opened this issue Mar 24, 2021 · 2 comments

Comments

@vRallev
Copy link

vRallev commented Mar 24, 2021

Expected Behavior

IntelliJ formats a top-level function like that:

private fun <T, U : LayerRendering> StatelessWorkflow<
  AuthenticatorInput, AuthenticatorOutput, LayeredScreen<PosLayering>
  >.RenderContext.renderChildToLayeredScreen(
  workflow: Workflow<T, Unit, U>,
  props: T
): LayeredScreen<MainAndModal> {
  ...
}

Observed Behavior

KtLint complains about:

file.kt:4:3: Unexpected indentation (expected 4, actual 2) (parameter-list-wrapping)
file.kt:5:3: Unexpected indentation (expected 4, actual 2) (parameter-list-wrapping)
file.kt:6:1: Unexpected indentation (expected 2, actual 0) (parameter-list-wrapping)

Changing the function to:

private fun <T, U : LayerRendering> StatelessWorkflow<
  AuthenticatorInput, AuthenticatorOutput, LayeredScreen<PosLayering>
  >.RenderContext.renderChildToLayeredScreen(
    workflow: Workflow<T, Unit, U>,
    props: T
  ): LayeredScreen<MainAndModal> {
  ...
}

will trigger these errors:

file.kt:4:1: Unexpected indentation (4) (should be 2) (indent)
file.kt:5:1: Unexpected indentation (4) (should be 2) (indent)
file.kt:6:1: Unexpected indentation (2) (should be 0) (indent)

Steps to Reproduce

See sample above.

Your Environment

  • Version of ktlint used: 0.41.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): custom Gradle task
  • Operating System and version: Mac / Linux
  • indent_size = 2
@romtsn romtsn added the bug label Apr 6, 2021
@ileasile
Copy link

Maybe the same bug:

build.gradle.kts:

tasks.test {
    systemProperties = mutableMapOf(
        "junit.jupiter.displayname.generator.default" to
            "org.junit.jupiter.api.DisplayNameGenerator\$ReplaceUnderscores",

        "junit.jupiter.execution.parallel.enabled" to
            doParallelTesting.toString() as Any,
        "junit.jupiter.execution.parallel.mode.default" to
            "concurrent",
        "junit.jupiter.execution.parallel.mode.classes.default" to
            "concurrent"
    )
}

ktlintFormat fails with:
Task :ktlintKotlinScriptFormat FAILED

C:\Projects\kotlin-jupyter\build.gradle.kts:178:9 Unexpected indentation (expected 4, actual 8)
C:\Projects\kotlin-jupyter\build.gradle.kts:181:5 Unexpected indentation (expected 4, actual 8)
C:\Projects\kotlin-jupyter\build.gradle.kts:183:1 Unexpected indentation (expected 4, actual 8)
C:\Projects\kotlin-jupyter\build.gradle.kts:184:27 Unexpected indentation (expected 4, actual 8)

Works fine for 0.40.0, bug was introduced in 0.41.0

@bethcutler
Copy link
Contributor

Another example (likely the same issue):

class Outer {
  class ExceptionallyParameterizedClass<
    ExceptionallyLongParameter1,
    ExceptionallyLongParameter2,
    ExceptionallyLongParameter3,
    ExceptionallyLongParameter4>
  private constructor(
    private val firstArgument: Type<ExceptionallyLongParameter1>,
    private val secondArgument: Type<ExceptionallyLongParameter3>
  ) {
    // foobar
  }
}

This gives Unexpected indentation (expected 2, actual 4) (parameter-list-wrapping) errors on both the parameter lines for the constructor, as well as the constructor's closing paren.

However, a similar example:

class Outer {
  class ExceptionallyParameterizedClass<ExceptionallyLongParameter1, ExceptionallyLongParameter2>
  private constructor(
    private val firstArgument: Type<ExceptionallyLongParameter1>,
    private val secondArgument: Type<ExceptionallyLongParameter3>
  ) {
    // foobar
  }
}

has no errors.

paul-dingemans pushed a commit to paul-dingemans/ktlint that referenced this issue Nov 10, 2021
Only the indentation rule should emit warnings about incorrect indentation to avoid
conflicting warnings from different rules about the indentation of the exact same
line. However, those other rules should still fix the indentation as good as they
can for the case that the indent rule is not run at all.

Closes pinterest#1267, pinterest#1119, pinterest#1045
@paul-dingemans paul-dingemans added this to the 0.44.0 milestone Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants