-
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 bydefault
.
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
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/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
.
if()
-statement per se cancels any indent caused by the predicate expression being wrapped.