Skip to content

Reformat before commit and partial reformat is not supported from IntelliJ plugin #573

Description

@celabou

Ktfmt intellij plugin does not account for line ranges nor declares Feature.FORMAT_FRAGMENTS in it's KtfmtFormattingService (see FormattingServiceUtil.findService).

As a result, using "reformat before commit", formatting a selected portion of the code or other partial reformatting from the IDE result in formatting that do not comply with Ktfmt, leading to inconsistent states and need for manual reformatting of our repo every once in a while.

Git hooks or full reformat before commit are a workaround but is not convenient (breaks committing only a part of a file's changes to VCS) and requires extra setup and computation.

Reproduction sample:

  • Committing with "Reformat code" commit check leads to the formatting below
  • Reformatting with Ktfmt changes indents and puts the first padding in the same line as Modifier
private fun MyComposeFunction() {
    Function(
        modifier =
        Modifier
            .padding(vertical = someVerticalPadding())
            .padding(vertical = someVerticalPadding())
    )
}

fun Function(
    modifier: Any,
): Unit = TODO()

fun someVerticalPadding(): Any = TODO()

interface Modifier {
    fun padding(vertical: Any): Modifier = TODO()

    companion object : Modifier
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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