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

The class-signature rule wrong wrapping in 1.3.0. #2708

Closed MaximSysoev closed 1 week ago

MaximSysoev commented 1 week ago

In 1.3.0 version class-signature rule begin force unwrapping class signature with 1 parameter if ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 2. In 1.2.1 it didn't it. It parameters count more than 2 it should force wrap it, but it seems, that this class has single parameter, so it could be either single-line or multi-line.

Expected Behavior

If I formatted this class as multi-line it should stay multi-line.

class TempData(
  val param: String,
)

Observed Behavior

As a result of formatting ktlint make class signature with 1 param a single line.

class TempData(val param: String)

Steps to Reproduce

Setup ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 2 Create any class with 1 parameter in the constructor. Press option+command+L

Your Environment

paul-dingemans commented 1 week ago

Sorry, this is not the way the rule works. Ktlint favors consistent formatting. So it will format all classes according to the same rule. When ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than is set to 2, all classes having 2 or more parameters will have their parameters wrapped on separate lines. At the same time, all classes having less than 2 parameter will be written as a single line unless the max_line_length is exceeded.

MaximSysoev commented 1 week ago

Ok, I see. Thank you for the answer.