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

Multiple statements on one line disallowed #2220

Closed
alex-shinn opened this issue Aug 31, 2023 · 8 comments · Fixed by #2222
Closed

Multiple statements on one line disallowed #2220

alex-shinn opened this issue Aug 31, 2023 · 8 comments · Fixed by #2222

Comments

@alex-shinn
Copy link

Expected Behavior

Code with multiple statements on one line separated with a semi-colon should be allowed, e.g.:

fun foo() {
    println("hello"); println("world")
}

Observed Behavior

Running ktlint on a file containing only the above code reports:

Missing newline after ";" (standard:wrapping)

Steps to Reproduce

$ cat Foo.kt 
fun foo() {
    println("hello"); println("world")
}
$ ktlint Foo.kt
Foo.kt:2:22: Missing newline after ";" (standard:wrapping)
15:45:55.696 [main] WARN com.pinterest.ktlint.cli.internal.KtlintCommandLine - Lint has found errors than can be autocorrected using 'ktlint --format'

Summary error count (descending) by rule:
  standard:wrapping: 1

Your Environment

  • Version of ktlint used: 0.50.0
  • Relevant parts of the .editorconfig settings: ktlint_standard_comment-wrapping = disabled
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): command line
  • Version of Gradle used (if applicable): NA
  • Operating System and version: Linux vm-ashinn2 5.15.0-1031-gcp #38-Ubuntu SMP Tue Feb 28 20:44:51 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
@paul-dingemans
Copy link
Collaborator

@paul-dingemans paul-dingemans closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2023
@alex-shinn
Copy link
Author

Thanks for the quick reply! And thanks for all your work on this project!

I'm already disabling rules selectively, but would prefer not to disable standard:wrapping, e.g. I want it to rewrite:

val x = f(
    a,
    b,
    c)

to

val x = f(
    a,
    b,
    c,
)

The logic also seems to differ for commas and semi-colons: foo(a, b, c) is ok but foo { a; b } is not. If it's too hard to fix this, would it be possible to use a different rule name for the semi-colon case?

@alex-shinn
Copy link
Author

P.S. this isn't an edge case, we use protobufs extensively and for short protobufs it's way too verbose for every constructor:

point { x = X; y = Y }

to be expanded out to 4 lines.

@paul-dingemans
Copy link
Collaborator

Oops, I did not read careful enough. I thought this was only done by the statement-wrapping rule and did not see that you mentioned that it is done by the wrapping rule. Disabling wrapping for this use case would be extreme. I will check it. But it is unlikely that it will be fixed in the 1.0 release as I am almost done with integration testing for that release.

@paul-dingemans paul-dingemans reopened this Sep 1, 2023
@paul-dingemans
Copy link
Collaborator

paul-dingemans commented Sep 1, 2023

Oops, I did not read careful enough. I thought this was only done by the statement-wrapping rule and did not see that you mentioned that it is done by the wrapping rule. Disabling wrapping for this use case would be extreme. I will check it. But it is unlikely that it will be fixed in the 1.0 release as I am almost done with integration testing for that release.

To make it even worse, the statement-wrapping was ought to cover splitting of statements on separate rules but currently only handles wrapping of statements that are on the same line as the opening or closing curly braces of a block but it fails to handle:

fun foo() {
       doSomething(); doSomething(); doSomething(); doSomething(); doSomething(); doSomething()
}

I vaguely recall some troubles with dependencies between wrapping and statement-wrapping rule and parked that to be resolved later.

@paul-dingemans
Copy link
Collaborator

P.S. this isn't an edge case, we use protobufs extensively and for short protobufs it's way too verbose for every constructor:

point { x = X; y = Y }

to be expanded out to 4 lines.

The Kotlin guideline are quite clear about this. https://kotlinlang.org/docs/coding-conventions.html#semicolons:

Omit semicolons whenever possible.

@paul-dingemans
Copy link
Collaborator

I decided to fix it in the 1.0. release as it was always the idea that this functionality would be provided by the new statement-wrapping rule. This was not done so in 0.50 as the statement-wrapping in that version was stil an experimental rule. Moving the semicolon wrapping from the (non-experimental) wrapping rule to the (experimental) statement-wrapping rule would have resulted in the loss of that functionality for projects that would not have enabled the experimental rule.
Now the statement-wrapping has been promoted to non-experimental, and the semicolon rule logic has been moved to this rule.

@alex-shinn
Copy link
Author

Thanks!

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

Successfully merging a pull request may close this issue.

2 participants