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

context receivers cause unexpected formatting of the function signature #2800

Closed
david-kubecka opened this issue Sep 18, 2024 · 1 comment · Fixed by #2814
Closed

context receivers cause unexpected formatting of the function signature #2800

david-kubecka opened this issue Sep 18, 2024 · 1 comment · Fixed by #2814

Comments

@david-kubecka
Copy link

Expected Behavior

Take the following function:

fun someFunction(longParam: String, longParam2: String, longParam3: String, longParam4: String) = 1

The formatting is accepted by ktlint (see config below). Adding a context receiver, I would expect no change in the formatting of the function signature:

context(String, Int, Long)
fun someFunction(longParam: String, longParam2: String, longParam3: String, longParam4: String) = 1

Observed Behavior

ktlint formats as follows:

context(String, Int, Long)
fun someFunction(
    longParam: String,
    longParam2: String,
    longParam3: String,
    longParam4: String,
) = 1

I believe ktlint wrongly treats the context as part of the signature when calculating its length because a slightly shorter version (fitting on a line including the context directive) is accepted:

context(String, Int)
fun someFunction(longParam: String, longParam2: String, longParam3: String, longParam4: String) = 1

Your Environment

  • ktlint version: 1.3.1
  • editorconfig
[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true

[*.{kt,kts}]
ktlint_code_style = ktlint_official
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = unset
@paul-dingemans paul-dingemans changed the title context receivers cause unexepceted formatting of the function signature context receivers cause unexpected formatting of the function signature Sep 24, 2024
@paul-dingemans
Copy link
Collaborator

I believe ktlint wrongly treats the context as part of the signature when calculating its length because a slightly shorter version (fitting on a line including the context directive) is accepted:

Your analysis is correct. Tnx for reporting.

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