Ktlint: Wrong new line check

Created on 20 Aug 2020  路  11Comments  路  Source: pinterest/ktlint

The bug you're experiencing might have already be reported!
Please search in the issues before creating one.

Expected Behavior


Method after multiline text

Observed Behavior

      """
            |longtext longtext longtext longtext longtext longtext
            |longtext longtext longtext longtext longtext longtext
            |longtext longtext longtext longtext longtext longtext
            |longtext longtext longtext longtext longtext longtext
            """.trimMargin("|")

Ktlint gives 2 error.

Argument should be on a separate line (unless all arguments can fit a single line)ktlintTestSourceSetCheck
Missing newline before ")"

Steps to Reproduce


  • Version of ktlint used: 0.38.0-alpha01
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): ktlintCheck from https://github.com/JLLeitschuh/ktlint-gradle
  • Version of Gradle used (if applicable): 6.6
  • Operating System and version: MacOs - 10.15.6
  • Link to your project (if it's a public repository):
argument-list-wrapping bug

All 11 comments

Thanks for the report @kozaxinan. To clarify: both errors are reporting on the """.trimMargin("|") line? And can you also confirm that this is a regression with the 0.38.0 alpha? (i.e. didn't occur in 0.37.2).

Yes that is a regression in alpha and yes it is on trimIndent line.

@kozaxinan I could not reproduce it with following Kotlin file:

val test =
"""
            |longtext longtext longtext longtext longtext longtext
            |longtext longtext longtext longtext longtext longtext
            |longtext longtext longtext longtext longtext longtext
            |longtext longtext longtext longtext longtext longtext
            """.trimMargin("|")

Maybe you could provide full Kotlin file or link to it?

class Test {

  fun someMethod(str: String) = Unit

  val someString = someMethod(
    """
    longtext longtext longtext longtext longtext longtext longtext longtext
    longtext longtext longtext longtext longtext longtext longtext longtext
    longtext longtext longtext longtext longtext longtext longtext longtext
    longtext longtext longtext longtext longtext longtext longtext longtext
    longtext longtext longtext longtext longtext longtext longtext longtext
    """.trimIndent('|')
  )
}

Running ktlint on this file gives two errors.

/Test.kt:14:20: Argument should be on a separate line (unless all arguments can fit a single line)
/Test.kt:14:23: Missing newline before ")"

@kozaxinan sorry, but you example only produces indentation errors for me with latest build from master:

Test.kt:3:1: Unexpected indentation (2) (should be 4)
Test.kt:5:1: Unexpected indentation (2) (should be 4)
Test.kt:6:1: Unexpected indentation (4) (should be 8)
Test.kt:6:5: Unexpected indentation (expected 6, actual 4)
Test.kt:13:1: Unexpected indentation (2) (should be 4)

Could you try 0.38.0 release?

I tested that code example with 0.38 and command line ktlint.

I will test issue in a fresh repo.

Do you have .editorconfig in your repo? Could you paste content of it here? It may affect ktlint results.

I checked code in empty folder outside of project without editorconfig.

Running 'ktlint --android' gives errors for me with 0.38

Yeah, with --android I could also reproduce it :+1:

@kozaxinan with 0.39.0 release you could disable experimental 'argument-list-wrapping' rule to suppress this issue.

Was this page helpful?
0 / 5 - 0 ratings