saveourtool / diktat

Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs
https://diktat.saveourtool.com
MIT License
521 stars 39 forks source link

Internal functional interface in Kotlin format in an uncompilable way #1775

Closed yonatankarp closed 8 months ago

yonatankarp commented 10 months ago

If you're just submitting a feature request or question, no need for the above.

When I'm using an internal functional interface, the formatting puts the fun keyword in front of the internal keyword causing the code to be un-compileable.

For example, the following class:

internal fun interface DragonSlayingStrategy {
    fun execute()
}

Will end up as follows after running spotless:

fun internal interface DragonSlayingStrategy {
    fun execute()
}

The above code using Spotless Gradle plugin (version 6.22.0) with this configuration:

spotless {
        kotlin {
            target(
                fileTree("${project.rootDir}/$name") {
                    include("**/*.kt")
                },
            )
            diktat("1.2.3").configFile("${rootProject.rootDir}/config/diktat/diktat-analysis.yml")
        }
    }

Here you can see the output log of the issue:

 @@ -3,6 +3,6 @@
/**
·*·Strategy·interface.
·*/
-internal·fun·interface·DragonSlayingStrategy·{
+fun·internal·interface·DragonSlayingStrategy·{
····fun·execute()
}

The issue was reported to Spotless and pin-point to dektat as can be seen in this Issue: https://github.com/diffplug/spotless/issues/1865

A code example that reproduces the issue can be found here: https://github.com/yonatankarp/spotless-bug-example

Please note that the issue still happens even when all costume configs are disabled.

nulls commented 10 months ago

@yonatankarp thanks for reporting the issue. We will look on it

diphtongue commented 8 months ago

This problem was solved in diktat-1.2.5. Please, move to diktat-2.0.0. However, if you need spotless, then move to diktat-1.2.5.

yonatankarp commented 8 months ago

Thanks @diphtongue ! Seems to solve the problem 🙏

I'm closing the issue