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

Using import aliases on static Java methods with reserved Kotlin keyword names trigger the Unused Import rule #937

Closed
gmetal opened this issue Oct 1, 2020 · 5 comments
Labels

Comments

@gmetal
Copy link

gmetal commented Oct 1, 2020

Expected Behavior

Mockito contains a static Java method names when, which will be imported in Kotlin like:

import org.mockito.Mockito.`when`

Clearly, if you try to use an import alias to get rid of the when, for example like:

import org.mockito.Mockito.`when` as _when

Observed Behavior

When using ktlint version >= 0.38.0, the above import triggers the no-unused-import rule. For ktlint versions up to 0.37.2 this was working properly.

Steps to Reproduce

Simply do an import alias on a Java static method (or even a variable) which is named as a reserved Kotlin keyword (has been reproduced with Mockito.when and org.hamcrest.CoreMatchers.is) and run ktlint. Note that the actual alias name given does not seem to matter.

Your Environment

  • Version of ktlint used: 0.38.0, 0.39.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Gradle plugin: org.jlleitschuh.gradle:ktlint-gradle:9.4.0
  • Version of Gradle used (if applicable): 5.6.4
  • Operating System and version: Debian Linux Buster
  • Link to your project (if it's a public repository):
@Tapchicoma Tapchicoma added the bug label Oct 1, 2020
@romtsn
Copy link
Collaborator

romtsn commented Oct 1, 2020

Should be fixed by #911, you can try a snapshot

@romtsn romtsn closed this as completed Oct 1, 2020
@gmetal
Copy link
Author

gmetal commented Oct 2, 2020

I tried the latest snapshot (ktlint-0.39.0-SNAPSHOT) and it appears that the issue is still there. I have created a sample app that demonstrates the issue here.

@romtsn
Copy link
Collaborator

romtsn commented Oct 2, 2020

oh, interesting, thanks for the sample 👍

@AndrewReitz
Copy link

This appears not to just be a static import of java methods but using import aliases in general. I was able to easily reproduce this.

package test.ktlint

import something as `It`

class Test {
    fun test() {
        It()
    }
}

@paul-dingemans
Copy link
Collaborator

Problem seems not be reproducable in at least version 0.43.2. If I recall correctly we solve d a bug a while ago in which import statements were removed when sorting the imports. Please reopen, if problem pop ups again.

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

No branches or pull requests

5 participants