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

Import ordering rule removing used imports #766

Closed
josephlbarnett opened this issue Jun 4, 2020 · 5 comments · Fixed by #768 or #779
Closed

Import ordering rule removing used imports #766

josephlbarnett opened this issue Jun 4, 2020 · 5 comments · Fixed by #768 or #779
Labels
Milestone

Comments

@josephlbarnett
Copy link

With the fix for #527 released in 0.37.0, looked to turn the import ordering rule on for our projects with idea format, and found the following:

Expected Behavior

With import ordering rule turned on (to idea format) via .editorconfig, running ktlint -F version 0.37.0 against https://github.com/trib3/leakycauldron/blob/master/json/src/test/kotlin/com/trib3/json/ObjectMapperTest.kt should not reformat the file.

Observed Behavior // Steps to reproduce

With import ordering rule turned on (to idea format) via .editorconfig, running ktlint -F version 0.37.0 against https://github.com/trib3/leakycauldron/blob/master/json/src/test/kotlin/com/trib3/json/ObjectMapperTest.kt results in assertk imports other than assertk.all being removed, which then makes the file fail to compile due to the missing imports.

With import ordering rule turned on via .editorconfig, running ktlint -F version 0.36.0 (no idea format exists in this version) against https://github.com/trib3/leakycauldron/blob/master/json/src/test/kotlin/com/trib3/json/ObjectMapperTest.kt results in the java/kotlin imports being moved up from the end into lexicographic order (as expected)

Your Environment

  • Version of ktlint used: 0.37.0 / 0.36.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Use maven plugin in general, but command line for the minimal test cases above
  • Version of Gradle used (if applicable): n/a
  • Operating System and version: ubuntu linux 20.04
  • Link to your project (if it's a public repository): https://github.com/trib3/leakycauldron
@Zayankovsky
Copy link

I'm still having issues with import aliases. This is my .editorconfig:

[*.{kt,kts}]
insert_final_newline=true
max_line_length=120
kotlin_imports_layout=idea

This file triggers import-ordering error:

import android.view.ViewGroup.LayoutParams.MATCH_PARENT as MATCH
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT as WRAP

fun main() {
    println(MATCH)
    println(WRAP)
}

running ktlint --android -F results in WRAP_CONTENT import being removed.
Ktlint version 0.37.1.

@romtsn
Copy link
Collaborator

romtsn commented Jun 11, 2020

@Zayankovsky sorry, apparently I'm having a hard time properly distinguish imports :D

@romtsn
Copy link
Collaborator

romtsn commented Jun 12, 2020

@Zayankovsky @josephlbarnett could you please check with the 0.38.0-SNAPSHOT version if your issues are gone? We'd like to release a patch version, but want to make sure there are no issues with imports anymore

@Zayankovsky
Copy link

@romtsn the issues are gone with the 0.38.0-SNAPSHOT version, thanks.

@josephlbarnett
Copy link
Author

our issues were fixed with 0.37.1, checking 0.38.0-SNAPSHOT shows that version working as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants