-
Notifications
You must be signed in to change notification settings - Fork 39
Mapping of flags which affect indentation
Context | Default value (diKTat) | Default value (IDEA) | diKTat | IntelliJ IDEA[1] | .editorconfig |
---|---|---|---|---|---|
Supertype ( |
???, see #1404 |
|
??? |
|
|
Function declaration parameters |
|
|
|
|
|
|
|
|
|
||
Function call arguments |
|
|
|
|
|
|
N/A[4] |
|
|
||
Chained function calls |
|
|
|
|
|
Conditions (particularly, |
|
|
|
|
|
Expression body functions |
|
|
|
|
|
Expressions
(such as |
|
|
N/A[6] |
||
Elvis ( |
|
N/A[4] |
|
|
There are actually three IDEA flags which control the continuation indent in function declarations:
-
CONTINUATION_INDENT_IN_PARAMETER_LISTS
,false
by default, -
ALIGN_MULTILINE_PARAMETERS
,true
by default, and -
METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
,true
by default.
These flags interact as follows:
-
METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
istrue
(the default), forced newline after the opening parenthesis:fun functionWithArguments( arg0: Int, arg1: Int, arg2: Int) = Unit
Formal parameters are indented according to the value of
CONTINUATION_INDENT_IN_PARAMETER_LISTS
and aligned; the actual value ofALIGN_MULTILINE_PARAMETERS
has no effect. Equivalent diKTat configuration:- name: WRONG_INDENTATION configuration: extendedIndentOfParameters: any (the desired value) alignedParameters: any (has no effect)
-
METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
isfalse
(no newline after the opening parenthesis),ALIGN_MULTILINE_PARAMETERS
istrue
(the default):fun functionWithArguments(arg0: Int, arg1: Int, arg2: Int) = Unit
In this case, the value of
CONTINUATION_INDENT_IN_PARAMETER_LISTS
has no effect at all. Equivalent diKTat configuration:- name: WRONG_INDENTATION configuration: extendedIndentOfParameters: any (has no effect) alignedParameters: true
-
METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
isfalse
(no newline after the opening parenthesis),ALIGN_MULTILINE_PARAMETERS
isfalse
:fun functionWithArguments(arg0: Int, arg1: Int, arg2: Int) = Unit
Formal parameters, except for the 1st one, are indented according to the value of
CONTINUATION_INDENT_IN_PARAMETER_LISTS
. Equivalent diKTat configuration:- name: WRONG_INDENTATION configuration: extendedIndentOfParameters: any (the desired value) alignedParameters: false
When within a predicate of an if
- or a while
-statement, IDEA ignores the
default (non-configurable) continuation indent (8 spaces) which is normally used
for expressions, and instead takes into account the value of
CONTINUATION_INDENT_IN_IF_CONDITIONS
.
Depending on the value of CONTINUATION_INDENT_IN_IF_CONDITIONS
flag, IDEA
may format long multi-line predicates either like this (continuation indent is
on):
fun f() {
if (true ||
false ||
true) {
// block body
}
if (1 +
2 +
3 +
4 == 10) {
// block body
}
while (true ||
false ||
true) {
// block body
}
do {
// block body
} while (true ||
false ||
true)
}
or like this (continuation indent is off, Kotlin Style Guide-recommended setting):
fun f() {
if (true ||
false ||
true) {
// block body
}
if (1 +
2 +
3 +
4 == 10) {
// block body
}
while (true ||
false ||
true) {
// block body
}
do {
// block body
} while (true ||
false ||
true)
}
The above implies the below is a correctly formatted code fragment, too (continuation indent is off):
fun f() {
if (
true)
return
}
If we set CONTINUATION_INDENT_IN_IF_CONDITIONS
on:
fun f() {
if (
true)
return
}
— then no compatible diKTat configuration will exist (the value of
extendedIndentAfterOperators
will make no difference here).
IDEA uses the values of both CONTINUATION_INDENT_IN_IF_CONDITIONS
and
CONTINUATION_INDENT_FOR_CHAINED_CALLS
to calculate the indent of chained
calls in conditions. Both flags are off (the default):
fun f() {
if (""
.isBlank()) {
return
}
}
Both flags are on:
fun f() {
if (""
.isBlank()) {
return
}
}
IDEA always uses the continuation indent for multi-line expressions, and this
can’t be configured (unless the user changes the value of
CONTINUATION_INDENT_SIZE
or ij_continuation_indent_size
):
(true ||
false ||
true ||
false ||
(true ||
false) ||
"".isEmpty())
(1 +
2 +
3 +
4)
(1 to
2 to
3)
val a = 42 as
Integer
val b = 42
as Integer
val c = 42 as?
Integer
val d = 42
as? Integer
val e = "" as
String
val f = ""
as String
val g = "" as?
String
val h = ""
as? String
The argument of a when
-expression:
when (true ||
false) {
true -> Unit
else -> Unit
}
The branch condition of a when
-expression:
when ("".isEmpty()) {
(true ||
false) -> Unit
else -> Unit
}
Infix function calls in a for
-loop:
for (i in 6 downTo
0 step
2) {
return
}
Operator function calls in a for
-loop:
for (i in 1..
42) {
return
}
Function call arguments:
fun f(): Int {
return g(1 +
2)
}
Expressions wrapped immediately after the opening parenthesis. Note the
continuation indent, even though CONTINUATION_INDENT_FOR_EXPRESSION_BODIES
may
be false
:
val v1 = (
true)
val v2 = (
1 + 2)
.idea/codeStyles/Project.xml
.
alignedParameters
is true
and there’s no newline after the opening parenthesis.
ALIGN_MULTILINE_PARAMETERS
is true
and METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
is false
at the same time.
if()
-statement per se cancels any indent caused by the predicate expression being wrapped.