diktat
diktat copied to clipboard
Fixing `WRONG_NEWLINES` rule with diktatFix does not set correct indents when `WRONG_INDENTATION` rule is disabled
I had to disable WRONG_INDENTATION rule because it still behaves unexpectedly. Please reopen https://github.com/saveourtool/diktat/issues/1312
I can imagine that it is correct behavior that auto correct WRONG_NEWLINES rule does not set the indents correctly (2 instead of 4) when WRONG_INDENTATION is disabled. Is there a correlation?
But anyway, there is still a strange behavior with WRONG_INDENTATION. For example Ktlint online does not report any WRONG_INDENTATION warnings while it does locally. Also checking the fix checkbox does fix the WRONG_NEWLINES properly, even with my config uploaded. But I'm pretty sure Ktlint online is buggy and does not respect the uploaded config file. It reports MAGIC_NUMBER, although I have disabled it in my config file.
When I enable WRONG_INDENTATION the indents are set properly for WRONG_NEWLINES when running diktatFix but then wrong indents are set at other places in the codebase. For example:
Box(
Modifier
.align(Alignment.CenterVertically)
.widthIn(min = 16.dp + 40.dp),
contentAlignment = Alignment.CenterStart,
)
becomes
Box(
Modifier
.align(Alignment.CenterVertically)
.widthIn(min = 16.dp + 40.dp),
contentAlignment = Alignment.CenterStart,
)
We also see that IntelliJ IDEA has changed a behaviour again. Previously we had implemented special flag to reproduce it's behaviour (extendedIndentAfterOperators). But now it is changed again, looks like they have fixed equals, but haven't fixed primitive operators +/-/*
for IDE this is ok:
5 +
7 + // <- 8 spaces (2 tab indents)
8
BUT the equal assignment in methods is working differently, even keeping in mind that it is an operator statement in AST:
fun foo() =
println() // <- 4 spaces (1 tab indent)
Our extendedIndentAfterOperators option is not changing ALL operators (INCLUDING =)
@0x6675636b796f75676974687562 pls make the logic similar to IDEA
@akuleshov7, the lack of continuation indent in your 2nd example (despite extendedIndentAfterOperators is on) is exactly #1330.
IDEA's code style flags are:
CONTINUATION_INDENT_FOR_EXPRESSION_BODIESandCONTINUATION_INDENT_IN_IF_CONDITIONS,
both are on by default as per the Kotlin code style guidelines.