Skip to content

Ktfmt 0.64 runs are not idempotent #640

Description

@lwasyl

The following test fails:

@Test
fun foo() {
  val code =
      """
      |//////////////////////////////////////////
      |fun test() {
      |  scope {
      |    val foo = 
      |      runCatching { someFunction() }.getOrNull()
      |  }
      |}
      |"""
          .trimMargin()

  val options = FormattingOptions(
    preserveLambdaBreaks = true,
    blockIndent = 2,
    continuationIndent = 2,
    maxWidth = code.lineSequence().first().length,
  )
  val formattedOnce = Formatter.format(
    options = options,
    code = code,
  )

  assertThatFormatting(formattedOnce)
      .withOptions(options)
      .isEqualTo(formattedOnce)
}

The first formatting produces

fun test() {
  scope {
    val foo = runCatching {
      someFunction()
    }.getOrNull()
  }
}

the second one does

fun test() {
  scope {
    val foo = runCatching {
      someFunction()
    }
      .getOrNull()
  }
}

(btw kind of surprised that the formatting isn't

val foo = runCatching { someFunction() }
  .getOrNull()

but I think that's intended? I mean the line break in lambda)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions