Skip to content

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

Closed as not planned

Description

@yonatankarp

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")
                },
            )
            // see https://github.com/shyiko/ktlint#standard-rules
            trimTrailingWhitespace()
            ktlint("1.0.1").editorConfigOverride(
                mapOf(
                    "ktlint_standard_package-name" to "disabled",
                    "ktlint_standard_enum-entry-name-case" to "disabled",
                    "ktlint_standard_trailing-comma" to "disabled",
                    "ktlint_standard_annotation" to "disabled",
                    "ktlint_standard_no-unused-imports" to "disabled",
                    "ktlint_standard_trailing-comma-on-call-site" to "disabled",
                    "ktlint_standard_trailing-comma-on-declaration-site" to "disabled",
                ),
            )
            diktat("1.2.3").configFile("${rootProject.rootDir}/config/diktat/diktat-analysis.yml")
        }
        kotlinGradle {
            target(
                fileTree(".") {
                    include("**/*.gradle.kts")
                },
            )
            trimTrailingWhitespace()
            indentWithTabs(2)
            indentWithSpaces(4)
            endWithNewline()
            ktlint()
        }
    }

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()
}

Activity

  1. Goooler commented on Nov 1, 2023

    @Goooler
    Member

    I can't repro it with Spotless or Ktlint CLI.

    Write DragonSlayingStrategy.kt

    internal fun interface DragonSlayingStrategy {
      fun execute()
    }
    

    Then

    ktlint -F DragonSlayingStrategy.kt

    Nothing changed.

  2. yonatankarp commented on Nov 1, 2023

    @yonatankarp
    Author

    I'll create a simple project that reproduce the problem and share it here when it's ready 👍

  3. yonatankarp commented on Nov 2, 2023

    @yonatankarp
    Author

    Hi @Goooler, here's the repo reproducing the issue I'm facing: https://github.com/yonatankarp/spotless-bug-example

    it's worth mentioning that while creating it I noticed the following:

    • When setting the project for a single module everything worked fine (as you've mentioned)
    • When setting it as a multi-module project, where Spotless is applied for each module via the build.gradle.kts in the root the problem re-appears in the example.

    It it 100% possible that I'm doing something wrong here and would be happy to hear if this is the case! 🙏

  4. Goooler commented on Nov 2, 2023

    @Goooler
    Member

    It's something related to

    diktat("1.2.3").configFile("${rootProject.rootDir}/config/diktat/diktat-analysis.yml")

    You can try ./gradlew spotlessApply after removing this line above.

  5. yonatankarp commented on Nov 2, 2023

    @yonatankarp
    Author

    Mmmm interesting, I'll try to figure out what are the where's the collision and open an issue for the diktat library 👍

  6. yonatankarp commented on Nov 3, 2023

    @yonatankarp
    Author

    Well, after carefully checking the custom config - even after disabling it completely and running it as follows the issue still exists:

    diktat("1.2.3")

    I'll open an issue for them 👍

  7. yonatankarp commented on Nov 6, 2023

    @yonatankarp
    Author

    Closing the loop: saveourtool/diktat#1775

    I'll close the ticket here once the issue would be solved so there would be no duplication by anyone else 😄

  8. yonatankarp commented on Dec 21, 2023

    @yonatankarp
    Author

    The issue can be resolved by using version 1.2.5 or above of Diktat. Please look at this example for more info.

    Closing the issue as the problem was resolved 😄

  9. Goooler commented on Dec 21, 2023

    @Goooler
    Member

    By the way, you can move to Diktat 2.0 after #1972 is finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions