Ktlint: Missing newline after `namedParameter="""string"""`

Created on 10 Sep 2020  路  3Comments  路  Source: pinterest/ktlint

Expected Behavior

I expect the following to pass formatting.

json(jsonString = """{ "id": "1234" }""")

Observed Behavior

Fails with: Missing newline after "=" (indent)

Steps to Reproduce

fun json(jsonString: String?) {
    TODO()
}

fun exampleThatFailsKtLint() {
    json(jsonString = """{ "id": "1234" }""")
}

fun exampleThatPassesKtLint() {
    // Android Studio formatting will move this back to next example, which will fail ktlint
    json(
        jsonString =
            """{ "id": "1234" }"""
    )
}

fun exampleThatFailsKtLintWhichAndroidStudioAutoFormatsTo() {
    json(
        jsonString =
        """{ "id": "1234" }"""
    )
}

fun exampleThatPassesLint() {
    // lacks named parameter
    json(
        """{ "id": "1234" }"""
    )
}
fun exampleThatPassesLint2() {
    // lacks named parameter
    json("""{ "id": "1234" }""")
}

Your Environment

  • Version of ktlint used: 0.38.1 (command line)
  • AS 4.0.1 with AGP 3.6
  • Operating System and version: MacOS 10.15.6
bug

All 3 comments

I also tried disabling this but it did not seem to work?

/* ktlint-disable indent */
json(jsonString = """{ "taskReferenceId": "1234" }""")
/* ktlint-enable indent */

I added this line.

import android.view.* // ktlint-disable no-wildcard-imports

Without the comment, I saw Wildcard import (cannot be auto-corrected) (no-wildcard-imports). After adding the comment, the error was suppressed. Seems like there is an issue with disabling the indent rule? I also checked with:

/* ktlint-disable no-wildcard-imports */
import android.view.*
/* ktlint-enable no-wildcard-imports */

Which worked as expected.

This is a separate issue probably

I could not reproduce your issue with build from current master. Most probably it was fixed via #711 issue.

Please open a separate issue regarding "indent" rule disabling is not working.

Yeah this is fixed already on master. Disabling the indent rule is also not possible at the moment as it runs all or nothing (only possible for the entire file), gonna be possible after we split it as mentioned in #764. Please look for the next release, we are planning to release 0.39.0 soon

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xenomachina picture xenomachina  路  5Comments

chao2zhang picture chao2zhang  路  4Comments

impatient picture impatient  路  5Comments

DanteAndroid picture DanteAndroid  路  3Comments

jeremymailen picture jeremymailen  路  3Comments