Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing WRONG_NEWLINES rule with diktatFix does not set correct indents when WRONG_INDENTATION rule is disabled #1323

Open
WebTiger89 opened this issue May 28, 2022 · 3 comments
Assignees
Labels
bug Something isn't working indentation Problems with `IndentationRule` (`WRONG_INDENTATION`)

Comments

@WebTiger89
Copy link

WebTiger89 commented May 28, 2022

I had to disable WRONG_INDENTATION rule because it still behaves unexpectedly. Please reopen #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,
)
@WebTiger89 WebTiger89 added the bug Something isn't working label May 28, 2022
@orchestr7
Copy link
Member

orchestr7 commented May 30, 2022

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 =)

@orchestr7
Copy link
Member

orchestr7 commented May 30, 2022

@0x6675636b796f75676974687562 pls make the logic similar to IDEA

@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added this to the 1.1.1 milestone May 31, 2022
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 changed the title Fixing WRONG_NEWLINES rule with diktatFix does not set correct idents when WRONG_INDENTATION rule is disabled Fixing WRONG_NEWLINES rule with diktatFix does not set correct idents when WRONG_INDENTATION rule is disabled Jun 1, 2022
@0x6675636b796f75676974687562
Copy link
Member

@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_BODIES and
  • CONTINUATION_INDENT_IN_IF_CONDITIONS,

both are on by default as per the Kotlin code style guidelines.

@0x6675636b796f75676974687562 0x6675636b796f75676974687562 changed the title Fixing WRONG_NEWLINES rule with diktatFix does not set correct idents when WRONG_INDENTATION rule is disabled Fixing WRONG_NEWLINES rule with diktatFix does not set correct indents when WRONG_INDENTATION rule is disabled Jun 29, 2022
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 removed this from the 1.2.4 milestone Aug 10, 2022
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added the indentation Problems with `IndentationRule` (`WRONG_INDENTATION`) label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working indentation Problems with `IndentationRule` (`WRONG_INDENTATION`)
Projects
None yet
Development

No branches or pull requests

3 participants