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

Accidental double-KDoc reported as consecutive line space problem #1802

Closed
JakeWharton opened this issue Jan 30, 2023 · 4 comments · Fixed by #1853
Closed

Accidental double-KDoc reported as consecutive line space problem #1802

JakeWharton opened this issue Jan 30, 2023 · 4 comments · Fixed by #1853

Comments

@JakeWharton
Copy link
Contributor

JakeWharton commented Jan 30, 2023

Expected Behavior

I have no idea. Maybe there should be a rule for this? Useless KDoc rule?

Observed Behavior

Consecutive blank line rule triggers despite there not being consecutive blank lines.

Steps to Reproduce

  /**
   * True to throw a [JsonDataException] on any attempt to call [skipValue].
   *
   * ## Getting
   * Returns true if this parser forbids skipping names and values.
   *
   * ## Setting
   * Configure whether this parser throws a [JsonDataException] when [skipValue] is
   * called. By default this parser permits values to be skipped.
   *
   * Forbid skipping to prevent unrecognized values from being silently ignored. This option is
   * useful in development and debugging because it means a typo like "locatiom" will be detected
   * early. It's potentially harmful in production because it complicates revising a JSON schema.
   */
  /** Returns true if this parser forbids skipping names and values. */
  @get:JvmName("failOnUnknown")
  public var failOnUnknown: Boolean = false
Step 'ktlint' found problem in 'moshi/src/main/java/com/squareup/moshi/JsonReader.kt':
Error on line: 219, column: 1
rule: no-consecutive-blank-lines
Needless blank line(s)

Your Environment

  • Version of ktlint used: 0.48.2
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Spotless spotApply task
@paul-dingemans
Copy link
Collaborator

I can not reproduce the problem with ktlint 0.48.2 with the given code sample. Can you try to reproduce with Ktlint CLI instead of spotless?

@JakeWharton
Copy link
Contributor Author

Uh it may require an additional property below it. Or above it?

But yes I'll try.

@JakeWharton
Copy link
Contributor Author

Okay here's a problematic snippet:

public class JsonReader {
  public var lenient: Boolean = false

  /**
   * Hey
   */
  /** Sup */
  @get:Synchronied
  public var failOnUnknown: Boolean = false
}
$ ktlint JsonReader.kt
JsonReader.kt:8:3: Declarations and declarations with annotations should have an empty space between. (spacing-between-declarations-with-annotations)

Summary error count (descending) by rule:
  spacing-between-declarations-with-annotations: 1

$ ktlint -F JsonReader.kt
JsonReader.kt:4:1: Needless blank line(s) (no-consecutive-blank-lines)
JsonReader.kt:8:4: Declarations and declarations with annotations should have an empty space between. (spacing-between-declarations-with-annotations)

Summary error count (descending) by rule:
  no-consecutive-blank-lines: 1
  spacing-between-declarations-with-annotations: 1

The act of formatting actually added the second blank line between properties because of the double KDoc.

index 529ab4c..d931a98 100644
--- JsonReader.kt
+++ JsonReader.kt
@@ -1,6 +1,7 @@
 public class JsonReader {
   public var lenient: Boolean = false

+
   /**
    * Hey
    */

@paul-dingemans
Copy link
Collaborator

paul-dingemans commented Jan 30, 2023

Tnx, this is reproducable.

Maybe there should be a rule for this? Useless KDoc rule?

Ktlint 0.49.0 will get a new rule no-consecutive-comments (#1454) which also detects consecutive KDoc's.

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

Successfully merging a pull request may close this issue.

2 participants