Skip to content

Commit

Permalink
Updated refs to latest (1.2.0) release (#2573)
Browse files Browse the repository at this point in the history
Co-authored-by: Ktlint Release Workflow <>
  • Loading branch information
paul-dingemans committed Feb 28, 2024
1 parent ab287d9 commit c25aa27
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 58 deletions.
4 changes: 2 additions & 2 deletions documentation/release-latest/docs/install/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ All releases of `ktlint` can be downloaded from the [releases](https://github.co
A particular version of `ktlint` can be downloaded with next command which also changes the file to an executable in directory `/usr/local/bin`:

```sh title="Download"
curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.1.1/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/
curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.2.0/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/
```

!!! tip "Curl not installed or behind proxy"
Expand Down Expand Up @@ -209,6 +209,6 @@ Options `--stdin` and `--patterns-from-stdin` are mutually exclusive, only one o

Microsoft Windows is not able to run the `ktlint` command directly. Ktlint can be run in following ways on Microsoft Windows:

1. Use the `ktlint.bat` batch file provided as part of the [release](https://github.com/pinterest/ktlint/releases/tag/1.1.1). Add the batch file to your `%PATH%` environment variable for easy access
1. Use the `ktlint.bat` batch file provided as part of the [release](https://github.com/pinterest/ktlint/releases/tag/1.2.0). Add the batch file to your `%PATH%` environment variable for easy access
2. Run `ktlint` using Git Bash
3. Run as `java -jar ktlint`
6 changes: 3 additions & 3 deletions documentation/release-latest/docs/install/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ See [cli usage](../cli) for arguments that can be supplied to `ktlint`.
<dependency>
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-cli</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>
</dependency>
<!-- additional 3rd party ruleset(s) can be specified here -->
</dependencies>
Expand Down Expand Up @@ -117,7 +117,7 @@ configurations {
}
dependencies {
ktlint("com.pinterest.ktlint:ktlint-cli:1.1.1") {
ktlint("com.pinterest.ktlint:ktlint-cli:1.2.0") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
}
Expand Down Expand Up @@ -167,7 +167,7 @@ The configuration below, defines following task:
val ktlint by configurations.creating

dependencies {
ktlint("com.pinterest.ktlint:ktlint-cli:1.1.1") {
ktlint("com.pinterest.ktlint:ktlint-cli:1.2.0") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
}
Expand Down
222 changes: 222 additions & 0 deletions documentation/release-latest/docs/rules/experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ ktlint_experimental=enabled
```
Also see [enable/disable specific rules](../configuration-ktlint/#disabled-rules).

### Backing property naming

Allows property names to start with `_` in case the property is a backing property. `ktlint_official` and `android_studio` code styles require the correlated property/function to be defined as `public`.

=== "[:material-heart:](#) Ktlint"

```kotlin
class Bar {
// Backing property
private val _elementList = mutableListOf<Element>()
val elementList: List<Element>
get() = _elementList
}
```
=== "[:material-heart-off-outline:](#) Disallowed"

```kotlin
class Bar {
// Incomplete backing property as public property 'elementList1' is missing
private val _elementList1 = mutableListOf<Element>()

// Invalid backing property as '_elementList2' is not a private property
val _elementList2 = mutableListOf<Element>()
val elementList2: List<Element>
get() = _elementList2
}
```

Rule id: `backing-property-naming` (`standard` rule set)

## Binary expression wrapping

Wraps binary expression at the operator reference whenever the binary expression does not fit on the line. In case the binary expression is nested, the expression is evaluated from outside to inside. If the left and right hand sides of the binary expression, after wrapping, fit on a single line then the inner binary expressions will not be wrapped. If one or both inner binary expression still do not fit on a single after wrapping of the outer binary expression, then each of those inner binary expressions will be wrapped.
Expand Down Expand Up @@ -45,6 +75,107 @@ Wraps binary expression at the operator reference whenever the binary expression

Rule id: `binary-expression-wrapping` (`standard` rule set)

## Blank lines between when-conditions

Consistently add or remove blank lines between when-conditions in a when-statement. A blank line is only added between when-conditions if the when-statement contains at lease one multiline when-condition. If a when-statement only contains single line when-conditions, then the blank lines between the when-conditions are removed.

!!! note
Ktlint uses `.editorconfig` property `ij_kotlin_line_break_after_multiline_when_entry` but applies it also on single line entries to increase consistency.

=== "[:material-heart:](#) Ktlint"

```kotlin
val foo1 =
when (bar) {
BAR1 -> "bar1"
BAR2 -> "bar2"
else -> null
}

// ij_kotlin_line_break_after_multiline_when_entry = true
val foo2 =
when (bar) {
BAR1 -> "bar1"

BAR2 -> {
"bar2"
}

else -> null
}

// ij_kotlin_line_break_after_multiline_when_entry = true
val foo3 =
when (bar) {
BAR1 -> "bar1"

// BAR2 comment
BAR2 -> "bar2"

else -> null
}

// ij_kotlin_line_break_after_multiline_when_entry = false
val foo4 =
when (bar) {
BAR1 -> "bar1"
BAR2 -> {
"bar2"
}
else -> null
}
```
=== "[:material-heart-off-outline:](#) Disallowed"

```kotlin
// ij_kotlin_line_break_after_multiline_when_entry = true | false (no blank lines in simple when-statement)
val foo1 =
when (bar) {
BAR1 -> "bar1"

BAR2 -> "bar2"

else -> null
}

// ij_kotlin_line_break_after_multiline_when_entry = true (missing newline after BAR1)
val foo2 =
when (bar) {
BAR1 -> "bar1"
BAR2 -> {
"bar2"
}

else -> null
}

// ij_kotlin_line_break_after_multiline_when_entry = true (missing newline after BAR1, and BAR2)
val foo3 =
when (bar) {
BAR1 -> "bar1"
// BAR2 comment
BAR2 -> "bar2"
else -> null
}

// ij_kotlin_line_break_after_multiline_when_entry = false (unexpected newline after BAR2)
val foo4 =
when (bar) {
BAR1 -> "bar1"
BAR2 -> {
"bar2"
}

else -> null
}
```

| Configuration setting | ktlint_official | intellij_idea | android_studio |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------:|:-------------:|:--------------:|
| `ij_kotlin_line_break_after_multiline_when_entry`<br/><i>Despite its name, forces a blank line between single line and multiline when-entries when at least one multiline when-entry is found in the when-statement.</i> | `true` | `true` | `true` |

Rule id: `blank-lines-between-when-conditions` (`standard` rule set)

## Chain method continuation

In a multiline method chain, the chain operators (`.` or `?.`) have to be aligned with each other.
Expand Down Expand Up @@ -541,6 +672,63 @@ Conditions should not use a both `&&` and `||` operators between operators at th

Rule id: `mixed-condition-operators` (`standard` rule set)

## KDoc

KDoc's should only be used on elements for which KDoc is to be transformed to documentation. Normal block comments should be used in other cases.

!!! note:
Access modifiers are ignored. Strictly speaking, one could argue that private declarations should not have a KDoc as no documentation will be generated for it. However, for internal use of developers the KDoc still serves documentation purposes.

=== "[:material-heart:](#) Ktlint"

```kotlin
/** some KDoc */
class FooBar(
/** some KDoc */
val foo: Foo
) {
/**
* Some bar KDoc
*/
constructor() : this()

/** some KDoc */
val bar: Bar
}

enum class Foo {
/** some KDoc */
BAR
}

/** some KDoc */
interface Foo
/** some KDoc */
fun foo()
/** some KDoc */
val foo: Foo
/** some KDoc */
object foo: Foo
/** some KDoc */
typealias FooBar = (Foo) -> Bar
```

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

```kotlin
/**
* Some dangling Kdoc (e.g. not followed by a declaration)
*/

val foo /** Some KDoc */ = "foo"

class Foo(
/** some dangling KDoc inside a parameter list */
)
```

Rule id: `kdoc` (`standard` rule set)

## Multiline loop

Braces required for multiline for, while, and do statements.
Expand All @@ -561,3 +749,37 @@ Braces required for multiline for, while, and do statements.
```

Rule id: `multiline-loop` (`standard` rule set)

## Square brackets spacing

Check for spacing around square brackets.

=== "[:material-heart:](#) Ktlint"

```kotlin
val foo1 = bar[1]
val foo2 =
bar[
1,
2,
]

@Foo(
fooBar = ["foo", "bar"],
fooBaz = [
"foo",
"baz",
],
)
fun foo() {}
```

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

```kotlin
val foo1 = bar [1]
val foo2 = bar[ 1]
val foo3 = bar[1 ]
```

Rule id: `square-brackets-spacing` (`standard` rule set)

0 comments on commit c25aa27

Please sign in to comment.