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

[0.40.0] experimental:spacing-between-declarations-with-comments false positives with // comments on class properties, variables and enum values #1053

Closed
mateuszkwiecinski opened this issue Jan 11, 2021 · 0 comments · Fixed by #1054
Labels
Milestone

Comments

@mateuszkwiecinski
Copy link
Contributor

mateuszkwiecinski commented Jan 11, 2021

Expected Behavior

I expect ktlint not to fail nor modify the code below when autoformatting. According to the issue linked in ktlint check, while Intellj indeed adds spacing between methods it doesn't between class properties, enum values, nor method variables.
Basically I expect spacing-between-declarations-with-comments not to report issues with a code that doesn't get autocorrected by IntelliJ.

Observed Behavior

ktlint fails with

SampleClass.kt:6:36: Declarations and declarations with comments should have an empty space between.

on every "// false positive" comment (below)

+ when executed with -F it adds spaces in places where intellij doesn't

before after formatting with ktlint
image image

Steps to Reproduce

Run ktlint on following code:

package com.doesnt.work.library

class SampleClass {

    private val public = "ok" // ok
    private val private = "not_ok" // false positive
    private val halfPublicHalfPrivate = "not_ok" // false positive

    /**
     * Doc 1
     */
    fun one() = 1

    /**
     * Doc 2
     */
    fun two() = 2
    fun three() {
        val public = "ok" // ok
        val private = "not_ok" // false positive
    }
}

enum class SampleEnum {
    One, // ok
    Two, // false positive
    Three, // false positive
}

Your Environment

configurations {
    ktlint
}

dependencies {
    ktlint "com.pinterest:ktlint:0.40.0"
}

task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    classpath = configurations.ktlint
    main = "com.pinterest.ktlint.Main"
    args "src/**/*.kt", "--experimental"
}
  • Version of ktlint used: 0.39.0 (works), 0.40.0 (doesn't work)
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): manually added Gradle tasks pasted above
  • Version of Gradle used (if applicable): 6.8
  • Operating System and version:
  • Link to your project (if it's a public repository):
@mateuszkwiecinski mateuszkwiecinski changed the title spacing-between-declarations-with-comments [0.40.0] experimental:spacing-between-declarations-with-comments false positives with // comments on class properties, variables and enum values Jan 11, 2021
@Tapchicoma Tapchicoma added the bug label Jan 14, 2021
@Tapchicoma Tapchicoma added this to the 0.41.0 milestone Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants