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

Function parameters are forcefully wrapped #2424

Closed
TWiStErRob opened this issue Dec 10, 2023 · 6 comments · Fixed by #2433
Closed

Function parameters are forcefully wrapped #2424

TWiStErRob opened this issue Dec 10, 2023 · 6 comments · Fixed by #2433

Comments

@TWiStErRob
Copy link
Contributor

TWiStErRob commented Dec 10, 2023

Expected Behavior

Code stays as it is, because it very clearly and easily fit on one line.

When class/function signature doesn't fit on a single line, each parameter must be on a separate line -- docs.

Observed Behavior

private fun BufferedSink.writeACTL(
    frameCount: Int,
    loopCount: Int,
) {
    writeChunk(ACTL) {
        writeInt(frameCount)
        writeInt(loopCount)
    }
}

Steps to Reproduce

ktlint "writeACTL.kt" --format

private fun BufferedSink.writeACTL(frameCount: Int, loopCount: Int) {
    writeChunk(ACTL) {
        writeInt(frameCount)
        writeInt(loopCount)
    }
}

Your Environment

  • Version of ktlint used: 1.0.1
  • Relevant parts of the .editorconfig settings: none
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): ktlint CLI
  • Version of Gradle used (if applicable): N/A
  • Operating System and version: Windows 10
@TWiStErRob TWiStErRob changed the title Function parameters are always forcefully wrapped Function parameters are always forcefully wrapped Dec 10, 2023
@TWiStErRob
Copy link
Contributor Author

Adding ktlint_standard_parameter-list-wrapping = disabled to the config doesn't change anything.

@TWiStErRob TWiStErRob changed the title Function parameters are always forcefully wrapped Function parameters are forcefully wrapped Dec 10, 2023
@paul-dingemans
Copy link
Collaborator

When you run ktlint without format, you can identify which rule is emitting the violation. In this case:

src/main/kotlin/Foo.kt:1:36: Newline expected after opening parenthesis (standard:function-signature)
src/main/kotlin/Foo.kt:1:53: Parameter should start on a newline (standard:function-signature)
src/main/kotlin/Foo.kt:1:67: Newline expected before closing parenthesis (standard:function-signature)

So, you are disabling the wrong rule.

@TWiStErRob
Copy link
Contributor Author

@paul-dingemans Before closing this, please note the fair? confusion based on documentation. There's an exact match with a meaningfully valid and relevant name for the problem I was facing:
https://pinterest.github.io/ktlint/latest/rules/standard/#parameter-list-wrapping

Maybe it's worth mentioning in the docs of parameter-list-wrapping here that this is not the only one that wraps the parameter list?


The disabling I mentioned was an attempted workaround based on the above (IMO very fair) assumption. The root cause here is again the changed default style which triggers the formatting on "2 or more parameters".

paul-dingemans added a commit that referenced this issue Dec 11, 2023
…signature` rules as both deal with wrapping parameters.

Closes #2424
paul-dingemans added a commit that referenced this issue Dec 11, 2023
…signature` rules as both deal with wrapping parameters. (#2433)

Closes #2424
@jlous
Copy link

jlous commented Jan 11, 2024

When you run ktlint without format, you can identify which rule is emitting the violation. In this case:

src/main/kotlin/Foo.kt:1:36: Newline expected after opening parenthesis (standard:function-signature)
src/main/kotlin/Foo.kt:1:53: Parameter should start on a newline (standard:function-signature)
src/main/kotlin/Foo.kt:1:67: Newline expected before closing parenthesis (standard:function-signature)

So, you are disabling the wrong rule.

How do you get the rule name in the output like that? I use "mvn ktlint:check" and am so tired of googling the messages to find the rule name. An why on earth are the messages not included in the docs, so you can find them there?

@paul-dingemans
Copy link
Collaborator

How do you get the rule name in the output like that?

This output is produced by Ktlint CLI (Plain Reporter). You can also use the ktlint-intelli-plugin for easy identification of the rule-id.

An why on earth are the messages not included in the docs, so you can find them there?

What about a lack of contributors? Feel free to contribute and maintain this kind of reference in the long run.

@jlous
Copy link

jlous commented Jan 12, 2024

You can also use the ktlint-intelli-plugin for easy identification of the rule-id.

Thanks. I also found out the maven plugin could be configured with "verbose" (for some reason it filters rule names by default)

Feel free to contribute and maintain this kind of reference in the long run.

Sorry, I just sort of assumed the rule docs were generated form the rule code. I see now they are manual .md files, and thus your point.

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.

3 participants