ktlint: Unnecessary import error for used imports with * at the end

Expected Behavior

No error

Observed Behavior

Error

Steps to Reproduce

Disable no-wildcard-imports rule and create a file with wildcard import

Your Environment

  • Version of ktlint used: 0.43.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): gradlew:ktlintCheck
  • Version of Gradle used (if applicable): 7.2
  • Operating System and version: Windows 10
  • Link to your project (if it’s a public repository): …

.editorconfig:

[*.{kt,kts}]
disabled_rules=no-wildcard-imports

Code:

import test.*

fun main() {
    Test1()
    Test2()
    Test3()
}

Output:

> Task :ktlintMainSourceSetCheck FAILED
D:\_sources\IDEA\tests\ktlint_error\src\main\kotlin\demo.kt:1:1 Unnecessary import
3 actionable tasks: 1 executed, 2 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':ktlintMainSourceSetCheck'.
> A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.ConsoleReportWorkAction
   > KtLint found code style violations. Please see the following reports:
     - D:\_sources\IDEA\tests\ktlint_error\build\reports\ktlint\ktlintMainSourceSetCheck\ktlintMainSourceSetCheck.txt

Fails only if run by the plugin task gradlew ktlintCheck. Does not fail if run ktlint from command line

Sample project: ktlint_error.zip

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 15
  • Comments: 18

Commits related to this issue

Most upvoted comments

My suggestion would be to revert the change that introduced this regression, and work from there. This way projects like kotlinter can continue to track the latest ktlint.