Skip to content

Commit

Permalink
Revert "Changed continuation_indent_size to 4"
Browse files Browse the repository at this point in the history
This reverts commit ed26117.

As per discussion from the GitHub issue [1], the default continuation
indent for Android should be 8 rather than 4. This matches the Android
Kotlin style guide.

[1] pinterest#120
  • Loading branch information
bradmcmanus committed Jan 3, 2018
1 parent fbfcbe8 commit 31c8e6c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ktlint recognizes the following [.editorconfig](http://editorconfig.org/) proper
# possible values: number (e.g. 2), "unset" (makes ktlint ignore indentation completely)
indent_size=4
# possible values: number (e.g. 2), "unset"
# it's automatically set to 8 on `ktlint --android ...` (per Android Kotlin Style Guide)
continuation_indent_size=unset
# true (recommended) / false
insert_final_newline=unset
Expand Down Expand Up @@ -264,6 +265,7 @@ Go to `File -> Settings... -> Editor`
- uncheck `Method declaration parameters -> Align when multiline`.
- (optional but recommended) open `Tabs and Indents` tab
- change `Continuation indent` to 4
(to be compliant with [Android Kotlin Style Guide](https://android.github.io/kotlin-guides/style.html) value should stay equal 8).
- `Inspections`
- change `Severity` level of `Unused import directive`, `Redundant semicolon` and (optional but recommended) `Unused symbol` to `ERROR`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class IndentationRule : Rule("indent") {
// indentation size recommended by JetBrains
private const val DEFAULT_INDENT = 4
private const val DEFAULT_CONTINUATION_INDENT = 4
// Android Kotlin Style Guide
private const val DEFAULT_CONTINUATION_INDENT_ANDROID = 8
}

private var indent = -1
Expand All @@ -43,7 +45,8 @@ class IndentationRule : Rule("indent") {
val indentSize = editorConfig.get("indent_size")
val continuationIndentSize = editorConfig.get("continuation_indent_size")
indent = indentSize?.toIntOrNull() ?: if (indentSize?.toLowerCase() == "unset") -1 else DEFAULT_INDENT
continuationIndent = continuationIndentSize?.toIntOrNull() ?: DEFAULT_CONTINUATION_INDENT
continuationIndent = continuationIndentSize?.toIntOrNull()
?: if (android) DEFAULT_CONTINUATION_INDENT_ANDROID else DEFAULT_CONTINUATION_INDENT
return
}
if (indent <= 0 || continuationIndent <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object IntellijIDEAIntegration {
}
val home = System.getProperty("user.home")
val editorConfig: Map<String, String> = EditorConfig.of(".") ?: emptyMap()
val continuationIndentSize = editorConfig["continuation_indent_size"]?.toIntOrNull() ?: 4
val continuationIndentSize = editorConfig["continuation_indent_size"]?.toIntOrNull() ?: if (android) 8 else 4
val indentSize = editorConfig["indent_size"]?.toIntOrNull() ?: 4
val codeStyleName = "ktlint${
if (continuationIndentSize == 4) "" else "-cis$continuationIndentSize"
Expand Down

0 comments on commit 31c8e6c

Please # to comment.