Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ij_kotlin_imports_layout with | generates multiple line breaks #1845

Closed
bcmedeiros opened this issue Mar 8, 2023 · 1 comment · Fixed by #1857
Closed

ij_kotlin_imports_layout with | generates multiple line breaks #1845

bcmedeiros opened this issue Mar 8, 2023 · 1 comment · Fixed by #1857
Labels
Milestone

Comments

@bcmedeiros
Copy link

Expected Behavior

I'm currently using the import-ordering rule with the following config:

ij_kotlin_imports_layout = *, |, javax.**, java.**, |, kotlinx.**, kotlin.**

I'd expect one of my files to be formatted like:

package test

import java.nio.file.Files
import java.nio.file.Paths
import java.util.Objects

object TestData {
    fun loadString(dataset: String): String {
        val path = Paths.get(Objects.requireNonNull(TestData::class.java.getResource(dataset)).toURI())
        return String(Files.readAllBytes(path))
    }
}

Observed Behavior

For some reason (I assume because of the two | in the layout config and not having any imports that match *), I got two extra line breaks in the file:

package test



import java.nio.file.Files
import java.nio.file.Paths
import java.util.Objects

object TestData {
    fun loadString(dataset: String): String {
        val path = Paths.get(Objects.requireNonNull(TestData::class.java.getResource(dataset)).toURI())
        return String(Files.readAllBytes(path))
    }
}

It seems that the number of extra line breaks is equals the number of | in the config, but if I remove the extra line breaks, I have to run ktlint -F twice until it stabilises, which makes the issue even worse.

Steps to Reproduce

Use the configuration and file above.

Your Environment

  • Version of ktlint used: 0.48.2
  • Relevant parts of the .editorconfig settings: (mentioned above)
@paul-dingemans
Copy link
Collaborator

This seems to be a regression bug in 0.48.2. It works fine with 0.48.1.

@paul-dingemans paul-dingemans added this to the 0.49.0 milestone Mar 8, 2023
paul-dingemans added a commit that referenced this issue Mar 13, 2023
…ayout` contains a `|` but no import exists that match any pattern before the first `|`

Closes #1845
paul-dingemans added a commit that referenced this issue Mar 14, 2023
…ayout` contains a `|` but no import exists that match any pattern before the first `|` (#1857)

Closes #1845
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants