Skip to content
New issue

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

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

Already on GitHub? # to your account

Can't reformat correctly in a round with trailing_comma_on_call_site enabled #1642

Closed
Goooler opened this issue Sep 10, 2022 · 2 comments · Fixed by #1648
Closed

Can't reformat correctly in a round with trailing_comma_on_call_site enabled #1642

Goooler opened this issue Sep 10, 2022 · 2 comments · Fixed by #1648

Comments

@Goooler
Copy link
Contributor

Goooler commented Sep 10, 2022

Expected Behavior

Reformat correctly in a round with trailing_comma_on_call_site enabled.

Observed Behavior

Need to format correctly code below for 3 times.

Original:

interface Foo {
  fun foo()
}

fun bar(foo: Foo) {
  foo.foo()
}

fun main() {
  bar(object : Foo {
      override fun foo() {
        TODO("Not yet implemented")
      }
  })
}

Steps to Reproduce

First round reformat:

fun main() {
  bar(object : Foo {
    override fun foo() {
      TODO("Not yet implemented")
    }
  },)
}

Second round reformat:

fun main() {
  bar(object : Foo {
    override fun foo() {
      TODO("Not yet implemented")
    }
  },
  )
}

Third round:

fun main() {
  bar(
    object : Foo {
      override fun foo() {
        TODO("Not yet implemented")
      }
    },
  )
}

You can start from the second step, also need 2 rounds to format.

Your Environment

  • Version of ktlint used: 0.47.1
  • Relevant parts of the .editorconfig settings https://github.com/Goooler/DemoApp/blob/trunk/.editorconfig
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): CLI
  • Version of Gradle used (if applicable): Nope
  • Operating System and version: MacOS 12.5.1
@Goooler Goooler changed the title Can't reformat correctly in a round Can't reformat correctly in a round with trailing_comma_on_call_site enabled Sep 10, 2022
@paul-dingemans paul-dingemans added this to the 0.48.0 milestone Sep 10, 2022
@vanniktech
Copy link
Contributor

Yep. Noticed this too. For instance here: https://github.com/vanniktech/gradle-code-quality-tools-plugin/pull/245/files#diff-7885ec759a167c69428552655473fc77195bb3733559c7e27bb3b2d26d36452aL21

Note though that I'm stuck on the second loop and it won't do the third and place object : Instantiator { into it's own line

@paul-dingemans
Copy link
Collaborator

In the examples above, the trailing comma should not have been added. Currently it is added because the VALUE_ARGUMENT_LIST is a multiline statement and any newline inside the VALUE_ARGUMENT_LIST is considered to be a reason to add the trailing comma.

paul-dingemans added a commit to paul-dingemans/ktlint that referenced this issue Sep 18, 2022
…er is only found inside a multiline argument. Only in case a newline character is found between arguments, this should be taken into account to add a trailing comma.

* Refactor and cleanup unused branches in isMultiline method

Closes pinterest#1642
paul-dingemans added a commit that referenced this issue Sep 22, 2022
…er is only found inside a multiline argument. Only in case a newline character is found between arguments, this should be taken into account to add a trailing comma. (#1648)

* Refactor and cleanup unused branches in isMultiline method

Closes #1642
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants