Paul Dingemans
12/20/2024, 8:12 PMMez Pahlan
12/20/2024, 8:44 PMPaul Dingemans
12/22/2024, 10:49 AM.editorconfig
settings? You might have something configured that is blocking the rule from executing the way you want it to run. Also, I am assuming that you run ktlint via its CLI.Mez Pahlan
12/22/2024, 5:08 PM.editorconfig
is also in that repo but the significant parts (at least in my head 😆 ) are:
max_line_length = 140
ktlint_code_style = intellij_idea
ktlint_standard_class-signature = enabled
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_standard_function-expression-body = disabled
ktlint_standard_multiline-expression-wrapping = disabled
To answer your question:
I am assuming that you run ktlint via its CLI.I do not. But I run it via the IntelliJ IDE plugin which is recommended in the KtLint page.
Can you provide more details about the version of ktlint you're using,I've tried with both version
1.3.1
(which we use at work) and 1.5.0
(which I am trying out locally).Paul Dingemans
12/23/2024, 10:51 AMktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 1
forces the class signature to be written as requested. But it will do this for any class signature having at least 1 parameters regardless whether the (single line) signature fits on one line or not.Mez Pahlan
12/23/2024, 10:56 AMktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = unset
• If class signature and single super type does not fit on a single line, wrap as if ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 1
Paul Dingemans
12/23/2024, 12:01 PMMez Pahlan
12/23/2024, 4:40 PMktlint_standard_class-signature = disabled
in that case.
And thank you for the explanations and insight 🙏 .Mez Pahlan
12/23/2024, 7:08 PMClasses with a few primary constructor parameters can be written in a single line:
Copy codeclass Person(id: Int, name: String)
Classes with longer headers should be formatted so that each primary constructor parameter is in a separate line with indentation. Also, the closing parenthesis should be on a new line. If you use inheritance, the superclass constructor call, or the list of implemented interfaces should be located on the same line as the parenthesis:
```class Person(
id: Int,
name: String,
surname: String
) : Human(id, name) { /*...*/ }```Specifically this:
If you use inheritance, the superclass constructor call, or the list of implemented interfaces should be located on the same line as the parenthesis:The test at the heart of this thread seems to contradict this convention as it moves the implemented interface to a newline below the closing parenthesis. I understand that setting
ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 1
gives me this behaviour for one or more parameters but according to that Kotlin convention I shouldn't need to force this setting. It should automatically kick it if the whole header exceeds the line limit.
I'm just interested in your thoughts at the moment I've got plenty of workarounds to be satisfied for now. Many thanks again, Paul!Paul Dingemans
12/23/2024, 8:05 PM