Skip to content

Commit

Permalink
Merge branch 'master' into 2286-mulitline-expression-wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-dingemans authored Oct 2, 2023
2 parents afbef10 + 95d95ee commit afe650b
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 140 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
* Ignore override of function in rule `function-naming` [#2271](https://github.com/pinterest/ktlint/issue/2271)
* Do not replace function body having a return statement only in case the return statement contains an intermediate exit point 'function-expression-body' [#2269](https://github.com/pinterest/ktlint/issue/2269)
* Prevent wrapping of nested multiline binary expression before operation reference as it results in a compilation error `multiline-expression-wrapping` [#2286](https://github.com/pinterest/ktlint/issue/2286)
* Force blank line before object declaration if preceded by another declaration `blank-line-before-declaration` [#2284](https://github.com/pinterest/ktlint/issues/2284)

### Changed

Expand Down
143 changes: 94 additions & 49 deletions documentation/snapshot/docs/rules/experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ Wraps binary expression at the operator reference whenever the binary expression
// Assume that the last allowed character is
// at the X character on the right X
if ((leftHandSideExpression && rightHandSideExpression) ||
(leftHandSideLongExpression &&
rightHandSideLongExpression)) {
(
leftHandSideLongExpression &&
rightHandSideExpression
)
) {
// do something
}
}
Expand All @@ -32,7 +35,9 @@ Wraps binary expression at the operator reference whenever the binary expression
fun foo() {
// Assume that the last allowed character is
// at the X character on the right X
if ((leftHandSideExpression && rightHandSideExpression) || (leftHandSideLongExpression && rightHandSideLongExpression)) {
if ((leftHandSideExpression && rightHandSideExpression) ||
(leftHandSideLongExpression && rightHandSideExpression)
) {
// do something
}
}
Expand Down Expand Up @@ -74,9 +79,10 @@ This rule can be configured with `.editorconfig` property [`ktlint_chain_method_
}?.map {
2 * it
}
val foo3 = foo().bar().map {
it.foobar()
}
val foo3 =
foo().bar().map {
it.foobar()
}
val foo4 =
"""
Some text
Expand Down Expand Up @@ -107,7 +113,8 @@ This rule can be configured with `.editorconfig` property [`ktlint_chain_method_
?.map {
2 * it
}
val foo3 = foo()
val foo3 =
foo()
.bar().map {
it.foobar()
}
Expand All @@ -133,96 +140,112 @@ The other code styles allow an infinite amount of parameters on the same line (a
```kotlin
// Assume that max_line_length is not exceeded when written as single line
class Foo0

class Foo1(
a: Any
a: Any,
)

class Foo2(
a: Any,
b: Any
b: Any,
)

class Foo3(
@Foo a: Any,
b: Any,
c: Any
c: Any,
)

class Foo4(
a: Any,
b: Any,
c: Any
c: Any,
) : FooBar(a, c)

class Foo5 :
FooBar(
"bar1",
"bar2",
) {
// body
}

class Foo6(
val bar1: Bar,
val bar2: Bar
val bar2: Bar,
) : FooBar(
bar1,
bar2
bar2,
) {
// body
}

class Foo7(
val bar1: Bar,
val bar2: Bar
val bar2: Bar,
) : FooBar(
bar1,
bar2
bar2,
),
BarFoo1,
BarFoo2 {
// body
}

class Foo8
constructor(
val bar1: Bar,
val bar2: Bar,
) : FooBar(bar1, bar2),
BarFoo1,
BarFoo2 {
// body
}
// body
}
```

=== "[:material-heart-off-outline:](#) Disallowed (ktlint_official)"

```kotlin
// Assume that max_line_length is not exceeded when written as single line
class Foo0()

class Foo1(a: Any)

class Foo2(a: Any, b: Any)

class Foo3(@Foo a: Any, b: Any, c: Any)

class Foo4(a: Any, b: Any, c: Any) : FooBar(a, c)

class Foo5 : FooBar(
"bar1",
"bar2",
) {
// body
}

class Foo6(
val bar1: Bar,
val bar2: Bar
val bar2: Bar,
) : FooBar(
bar1,
bar2
bar2,
) {
// body
}

class Foo7(
val bar1: Bar,
val bar2: Bar
val bar2: Bar,
) : FooBar(
bar1,
bar2
bar2,
),
BarFoo1,
BarFoo2 {
// body
}

class Foo8
constructor(
val bar1: Bar,
Expand All @@ -240,18 +263,25 @@ The other code styles allow an infinite amount of parameters on the same line (a
// Assume that the last allowed character is
// at the X character on the right X
class Foo0

class Foo1(
a: Any
a: Any,
)

class Foo2(a: Any)

class Foo3(
a: Any,
b: Any
b: Any,
)

class Foo4(a: Any, b: Any)

class Foo5(@Foo a: Any, b: Any, c: Any)

class Foo6(a: Any, b: Any, c: Any) :
FooBar(a, c)

class Foo7 : FooBar(
"bar1",
"bar2",
Expand All @@ -260,16 +290,17 @@ The other code styles allow an infinite amount of parameters on the same line (a
}
class Foo8(
val bar1: Bar,
val bar2: Bar
val bar2: Bar,
) : FooBar(
bar1,
bar2
) {
// body
}

class Foo9(
val bar1: Bar,
val bar2: Bar
val bar2: Bar,
) : FooBar(
bar1,
bar2
Expand All @@ -278,6 +309,7 @@ The other code styles allow an infinite amount of parameters on the same line (a
BarFoo2 {
// body
}

class Foo10
constructor(
val bar1: Bar,
Expand All @@ -295,6 +327,7 @@ The other code styles allow an infinite amount of parameters on the same line (a
// Assume that the last allowed character is
// at the X character on the right X
class Foo0()

class Foo6(a: Any, b: Any, c: Any) : FooBar(a, c)
```

Expand All @@ -311,20 +344,27 @@ Rewrites a function body only containing a `return` or `throw` expression to an

```kotlin
fun foo1() = "foo"

fun foo2(): String = "foo"

fun foo3(): Unit = throw IllegalArgumentException("some message")

fun foo4(): Foo = throw IllegalArgumentException("some message")

fun foo5() {
return "foo" // some comment
}

fun foo6(): String {
/* some comment */
return "foo"
}

fun foo7() {
throw IllegalArgumentException("some message")
/* some comment */
}

fun foo8(): Foo {
throw IllegalArgumentException("some message")
// some comment
Expand All @@ -336,12 +376,15 @@ Rewrites a function body only containing a `return` or `throw` expression to an
fun foo1() {
return "foo"
}

fun foo2(): String {
return "foo"
}

fun foo3() {
throw IllegalArgumentException("some message")
}

fun foo4(): Foo {
throw IllegalArgumentException("some message")
}
Expand All @@ -358,33 +401,33 @@ If the function literal contains multiple parameter and at least one parameter o
=== "[:material-heart:](#) Ktlint"

```kotlin
val foobar1 = { foo + bar }
val foobar2 =
{
foo + bar
}
val foobar3 =
{ foo: Foo ->
foo.repeat(2)
}
val foobar4 =
{ foo: Foo, bar: Bar ->
foo + bar
}
val foobar5 = { foo: Foo, bar: Bar -> foo + bar }
val foobar6 =
{
foo: Foo,
bar: Bar
->
foo + bar
}

val foobar1 = { foo + bar }
val foobar2 =
{
foo + bar
}
val foobar3 =
{ foo: Foo ->
foo.repeat(2)
}
val foobar4 =
{ foo: Foo, bar: Bar ->
foo + bar
}
val foobar5 = { foo: Foo, bar: Bar -> foo + bar }
val foobar6 =
{
foo: Foo,
bar: Bar,
->
foo + bar
}
// Assume that the last allowed character is
// at the X character on the right X
val foobar7 =
barrrrrrrrrrrrrr {
fooooooooooooooo: Foo
barrrrrrrrrrrrrr {
fooooooooooooooo: Foo
->
foo.repeat(2)
}
Expand Down Expand Up @@ -424,13 +467,15 @@ Enforce a single whitespace between the modifier list and the function type.

```kotlin
val foo: suspend () -> Unit = {}

suspend fun bar(baz: suspend () -> Unit) = baz()
```

=== "[:material-heart-off-outline:](#) Disallowed"

```kotlin
val foo: suspend() -> Unit = {}

suspend fun bar(baz: suspend () -> Unit) = baz()
```

Expand Down
Loading

0 comments on commit afe650b

Please sign in to comment.