pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.06k stars 504 forks source link

ktlint_function_signature_body_expression_wrapping configuration doesn't work via .editorconfig #2678

Closed aivanovski closed 1 month ago

aivanovski commented 1 month ago

Expected Behavior

Function declaration should be multiline. The changing of existing parameters in .editorconfig doesn't lead to expected result. The debug output of ktlint is here ktlint-output.txt

fun someFunction(
    a: Int,
    b: Int,
    c: Int
): Int {
    return a + b + c
}

Observed Behavior

Function declaration is single line

fun someFunction(a: Int, b: Int, c: Int): Int {
    return a + b + c
}

Steps to Reproduce

1 - install ktlint 2 - create .editorconfig file with output of command: ktlint generateEditorConfig --code-style android_studio 3 - change ktlint_function_signature_body_expression_wrapping to multiline 4 - format the code ktlint --editorconfig=".editorconfig" --format --log-level=debug

Your Environment

ktlint v1.2.1

paul-dingemans commented 1 month ago

Your example code does have a block body instead of an expression body. So the .editorconfig property ktlint_function_signature_body_expression_wrapping has no effect on that example.

When using code style android_studio, the function signature can contain any number of parameters in a single line as long as the entire signature fits on the single line. If you always want to wrap signature containing multiple parameters, you will need to set property ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than to 2. See https://pinterest.github.io/ktlint/latest/rules/standard/#function-signature

In case it still does not work as expected, please post your .editorconfig. Also make sure to explicitly save .editorconfig after changing it, and before running ktlint again.

aivanovski commented 1 month ago

It works, thank you!