Skip to content

Commit 17a240d

Browse files
Fix documentation class-signature (#2729)
Closes #2713
1 parent 91d8d44 commit 17a240d

File tree

2 files changed

+114
-56
lines changed

2 files changed

+114
-56
lines changed

documentation/release-latest/docs/rules/standard.md

+57-28
Original file line numberDiff line numberDiff line change
@@ -462,62 +462,80 @@ The other code styles allow an infinite amount of parameters on the same line (a
462462
// Assume that the last allowed character is
463463
// at the X character on the right X
464464
class Foo0
465-
465+
466+
// Entire class signature does not fit on single line
466467
class Foo1(
467-
a: Any,
468+
aVeryLonggggggggggggggggggggggg: Any
468469
)
469-
470+
471+
// Entire class signature does fit on single line
470472
class Foo2(a: Any)
471-
473+
474+
// Entire class signature does not fit on single line
472475
class Foo3(
473-
a: Any,
474-
b: Any,
476+
aVeryLonggggggggggggggg: Any,
477+
b: Any
475478
)
476-
479+
480+
// Entire class signature does fit on single line
477481
class Foo4(a: Any, b: Any)
478-
482+
483+
// Entire class signature does fit on single line
479484
class Foo5(@Foo a: Any, b: Any, c: Any)
480-
485+
486+
// Entire class signature does fit on single line
481487
class Foo6(a: Any, b: Any, c: Any) :
482488
FooBar(a, c)
483-
484-
class Foo7 : FooBar(
485-
"bar1",
486-
"bar2",
487-
) {
489+
490+
// Entire class signature (without constructor invocation) does fit on single line
491+
class Foo7 :
492+
FooBar(
493+
"bar1",
494+
"bar2"
495+
) {
488496
// body
489497
}
490-
class Foo8(
491-
val bar1: Bar,
492-
val bar2: Bar,
493-
) : FooBar(
494-
bar1,
495-
bar2
496-
) {
498+
499+
// Entire class signature (without constructor invocation) does fit on single line
500+
class Foo8(val bar1: Bar, val bar2: Bar) :
501+
FooBar(
502+
bar1,
503+
bar2
504+
) {
497505
// body
498506
}
499-
507+
508+
// Entire class signature (without constructor invocation) does not fit on single line
500509
class Foo9(
501-
val bar1: Bar,
502-
val bar2: Bar,
510+
val aVeryLonggggggggggggggg: Bar,
511+
val bar2: Bar
503512
) : FooBar(
504513
bar1,
505514
bar2
506-
),
515+
) {
516+
// body
517+
}
518+
519+
class Foo10(val bar1: Bar, val bar2: Bar) :
520+
FooBar(
521+
bar1,
522+
bar2
523+
),
507524
BarFoo1,
508525
BarFoo2 {
509526
// body
510527
}
511-
512-
class Foo10
528+
529+
class Foo11
513530
constructor(
514531
val bar1: Bar,
515-
val bar2: Bar,
532+
val bar2: Bar
516533
) : FooBar(bar1, bar2),
517534
BarFoo1,
518535
BarFoo2 {
519536
// body
520537
}
538+
521539
```
522540

523541
=== "[:material-heart-off-outline:](#) Disallowed (non ktlint_official)"
@@ -528,6 +546,14 @@ The other code styles allow an infinite amount of parameters on the same line (a
528546
class Foo0()
529547

530548
class Foo6(a: Any, b: Any, c: Any) : FooBar(a, c)
549+
550+
// Entire class signature (without constructor invocation) does fit on single line
551+
class Foo7 : FooBar(
552+
"bar1",
553+
"bar2",
554+
) {
555+
// body
556+
}
531557
```
532558

533559
| Configuration setting | ktlint_official | intellij_idea | android_studio |
@@ -536,6 +562,9 @@ The other code styles allow an infinite amount of parameters on the same line (a
536562

537563
Rule id: `standard:class-signature`
538564

565+
!!! warn
566+
For code styles `android_studio` and `intellij_idea` this rule rewrites multiline class signature to a single line class signature in case the entire class signature fits on a single line by default. In case you want to leave it to the discretion of the developer to decider whether a single or a multiline class signature is used, please suppress or disable this rule.
567+
539568
Suppress or disable rule (1)
540569
{ .annotate }
541570

documentation/snapshot/docs/rules/standard.md

+57-28
Original file line numberDiff line numberDiff line change
@@ -462,62 +462,80 @@ The other code styles allow an infinite amount of parameters on the same line (a
462462
// Assume that the last allowed character is
463463
// at the X character on the right X
464464
class Foo0
465-
465+
466+
// Entire class signature does not fit on single line
466467
class Foo1(
467-
a: Any,
468+
aVeryLonggggggggggggggggggggggg: Any
468469
)
469-
470+
471+
// Entire class signature does fit on single line
470472
class Foo2(a: Any)
471-
473+
474+
// Entire class signature does not fit on single line
472475
class Foo3(
473-
a: Any,
474-
b: Any,
476+
aVeryLonggggggggggggggg: Any,
477+
b: Any
475478
)
476-
479+
480+
// Entire class signature does fit on single line
477481
class Foo4(a: Any, b: Any)
478-
482+
483+
// Entire class signature does fit on single line
479484
class Foo5(@Foo a: Any, b: Any, c: Any)
480-
485+
486+
// Entire class signature does fit on single line
481487
class Foo6(a: Any, b: Any, c: Any) :
482488
FooBar(a, c)
483-
484-
class Foo7 : FooBar(
485-
"bar1",
486-
"bar2",
487-
) {
489+
490+
// Entire class signature (without constructor invocation) does fit on single line
491+
class Foo7 :
492+
FooBar(
493+
"bar1",
494+
"bar2"
495+
) {
488496
// body
489497
}
490-
class Foo8(
491-
val bar1: Bar,
492-
val bar2: Bar,
493-
) : FooBar(
494-
bar1,
495-
bar2
496-
) {
498+
499+
// Entire class signature (without constructor invocation) does fit on single line
500+
class Foo8(val bar1: Bar, val bar2: Bar) :
501+
FooBar(
502+
bar1,
503+
bar2
504+
) {
497505
// body
498506
}
499-
507+
508+
// Entire class signature (without constructor invocation) does not fit on single line
500509
class Foo9(
501-
val bar1: Bar,
502-
val bar2: Bar,
510+
val aVeryLonggggggggggggggg: Bar,
511+
val bar2: Bar
503512
) : FooBar(
504513
bar1,
505514
bar2
506-
),
515+
) {
516+
// body
517+
}
518+
519+
class Foo10(val bar1: Bar, val bar2: Bar) :
520+
FooBar(
521+
bar1,
522+
bar2
523+
),
507524
BarFoo1,
508525
BarFoo2 {
509526
// body
510527
}
511-
512-
class Foo10
528+
529+
class Foo11
513530
constructor(
514531
val bar1: Bar,
515-
val bar2: Bar,
532+
val bar2: Bar
516533
) : FooBar(bar1, bar2),
517534
BarFoo1,
518535
BarFoo2 {
519536
// body
520537
}
538+
521539
```
522540

523541
=== "[:material-heart-off-outline:](#) Disallowed (non ktlint_official)"
@@ -528,6 +546,14 @@ The other code styles allow an infinite amount of parameters on the same line (a
528546
class Foo0()
529547

530548
class Foo6(a: Any, b: Any, c: Any) : FooBar(a, c)
549+
550+
// Entire class signature (without constructor invocation) does fit on single line
551+
class Foo7 : FooBar(
552+
"bar1",
553+
"bar2",
554+
) {
555+
// body
556+
}
531557
```
532558

533559
| Configuration setting | ktlint_official | intellij_idea | android_studio |
@@ -536,6 +562,9 @@ The other code styles allow an infinite amount of parameters on the same line (a
536562

537563
Rule id: `standard:class-signature`
538564

565+
!!! warn
566+
For code styles `android_studio` and `intellij_idea` this rule rewrites multiline class signature to a single line class signature in case the entire class signature fits on a single line by default. In case you want to leave it to the discretion of the developer to decider whether a single or a multiline class signature is used, please suppress or disable this rule.
567+
539568
Suppress or disable rule (1)
540569
{ .annotate }
541570

0 commit comments

Comments
 (0)