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

Formatting not consistent with idea / AS #775

Closed
PaulWoitaschek opened this issue Jun 9, 2020 · 5 comments · Fixed by #792
Closed

Formatting not consistent with idea / AS #775

PaulWoitaschek opened this issue Jun 9, 2020 · 5 comments · Fixed by #792
Assignees
Labels
Milestone

Comments

@PaulWoitaschek
Copy link
Contributor

The following file is formatted correctly according to ktlint:

import java.time.LocalDate
import java.time.temporal.ChronoUnit

fun test() {
    val lastActive = LocalDate.now()
    if (lastActive != null && ChronoUnit.DAYS.between(
        lastActive,
        LocalDate.now()
    ) > 30
    ) {
        println("hello")
    }
}

I applied ktlints configuration to idea using:
ktlint applyToIDEA

When now formatting the code using idea, it generates a different intendation:

diff --git a/src/main/kotlin/test.kt b/src/main/kotlin/test.kt
index 5c49ec7..fcb3329 100644
--- a/src/main/kotlin/test.kt
+++ b/src/main/kotlin/test.kt
@@ -4,9 +4,9 @@ import java.time.temporal.ChronoUnit
 fun test() {
     val lastActive = LocalDate.now()
     if (lastActive != null && ChronoUnit.DAYS.between(
-        lastActive,
-        LocalDate.now()
-    ) > 30
+            lastActive,
+            LocalDate.now()
+        ) > 30
     ) {
         println("hello")
     }

I created a sample project here: https://github.com/PaulWoitaschek/KtLintFormattingBug
Versions:

  • ktlint 0.37.1
  • Android Studio 4.0 / idea 2020.2.1
@Tapchicoma Tapchicoma added the bug label Jun 9, 2020
@Tapchicoma Tapchicoma self-assigned this Jun 9, 2020
@Tapchicoma Tapchicoma added this to the 0.38.0 milestone Jun 9, 2020
@Tapchicoma
Copy link
Collaborator

Yes, continuation indent size is set to 8:

<option name="CONTINUATION_INDENT_SIZE" value="8" />

Will update it to 4

@PaulWoitaschek
Copy link
Contributor Author

I don't get it. Isn't that for xml?

@Tapchicoma
Copy link
Collaborator

I don't get it. Isn't that for xml?

No, it is for kotlin files. applyToIDEA just writes two xml files (Project.xml and ktlint.xml) into ./.idea/codeStyles/ folder. This xml files are pretty simple and may not reflect what actual rules expect.

See #701 for possible solution how to improve this situation.

@PaulWoitaschek
Copy link
Contributor Author

The line you posted:

    <codeStyleSettings language="XML">
      <indentOptions>
        <option name="CONTINUATION_INDENT_SIZE" value="8" />
      </indentOptions>
    </codeStyleSettings>

is definately for xml or am I missing something?

@Tapchicoma
Copy link
Collaborator

Yeah, this one for xml, few lines below the same for kotlin:

<option name="CONTINUATION_INDENT_SIZE" value="8" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants