pinterest / ktlint

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

Method Signature forcing multiline despite unset [`function_signature_rule_force_multiline`] #2613

Closed Lucky38i closed 6 months ago

Lucky38i commented 6 months ago

Expected Behavior

So currently in my .editorconfig I have set, among others, the following

ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = unset
ktlint_function_signature_body_expression_wrapping = default

Below is my expectation

@Operation(summary = "random Events Handler", description = "Endpoints for receiving random events")
@ApiResponse(responseCode = "200")
@PostMapping("/random")
fun handleEvent(@RequestBody event: Event) = service.handleEvents(event)

Observed Behavior

I have a method with one parameter that has an expression that is within my 140 character limit, and yet ktlint formats to add a new line within the parantheses as-well as a comma after the first parameter. I've scoured the ruleset and tried modifying values to no avail.

Ktlint formats as

@Operation(summary = "RandomEvents Handler", description = "Endpoints for receiving random events")
@ApiResponse(responseCode = "200")
@PostMapping("/random")
fun handleEvent(
    @RequestBody event: Event,
) = service.handleEvents(event)

So it properly retains the expression to one line, but the signature get's placed on a multiline. Maybe I'm not fully understanding the documentation, but I have tried it to various setting with no luck

Steps to Reproduce

Your Environment

General Configuration

indent_size = 4 indent_style = space insert_final_newline = true max_line_length = 140 end_of_line = lf

Intellij Configuration

ij_kotlin_allow_trailing_comma = true ij_kotlin_allow_trailing_comma_on_call_site = true ij_kotlin_packages_to_use_import_on_demand = *,java.,javax.,kotlin.*,^ ij_kotlin_imports_layout = ,java.,javax.,kotlin.**,^ ij_kotlin_line_break_after_multiline_when_entry = true


* Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): N/A as occurs with ktlint intellij plugin as-well
* Version of Gradle used (if applicable): `v7.4.2`
* Operating System: `Windows 10`
* Version: `10.0.22631 Build 22631`
paul-dingemans commented 6 months ago

This is expected behavior. Annotated parameters are always wrapped by the parameter-list-wrapping rule. https://pinterest.github.io/ktlint/latest/rules/standard/#parameter-list-wrapping