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

IndentationRule uses wrong continuation intendation #379

Closed
vanniktech opened this issue Apr 17, 2019 · 9 comments
Closed

IndentationRule uses wrong continuation intendation #379

vanniktech opened this issue Apr 17, 2019 · 9 comments

Comments

@vanniktech
Copy link
Contributor

When using the --experimental flag with ktlint 0.31.0 and the following configuration:

[*.{kt,kts}]
indent_size=2
max_line_length=200

the following code is flagged:

package com.vanniktech.color

import org.assertj.core.api.Java6Assertions.assertThat
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import java.awt.Color

class ColorExtensionsSpek : Spek({
  describe("color extensions") {
    mapOf(
        Color.RED to "#FF0000",
        Color.GREEN to "#00FF00",
        Color.BLUE to "#0000FF",
        Color.CYAN to "#00FFFF"
    ).forEach { color, string ->
      it("should convert rgb int color correctly to hex string") {
        assertThat(color.rgb.colorAsHex()).isEqualTo(string)
      }
    }
  }
})

This is the output:

ColorExtensionsSpek.kt:11:1: Unexpected indentation (8) (should be 6)
ColorExtensionsSpek.kt:12:1: Unexpected indentation (8) (should be 6)
ColorExtensionsSpek.kt:13:1: Unexpected indentation (8) (should be 6)
ColorExtensionsSpek.kt:14:1: Unexpected indentation (8) (should be 6)

The indentation should not be 6 though since it's on a new line and should be using continuation indentation which is 8.

@shashachu
Copy link
Contributor

@vanniktech I believe since the Kotlin Android styledocs removed any mention of continuation indent, the indentation formatter does not use a separate continuation intent. It will simply do a +indent_size

@vanniktech
Copy link
Contributor Author

It really should do a multiplication by two. Shouldn't it?

@NightlyNexus
Copy link
Contributor

I haven't seen examples of Kotlin styles using separate rules for continuation indents over normal indents. if you see it in a Google or JetBrains style guide, can you post the link?

@shashachu
Copy link
Contributor

Closing this for now because a continuation indent is not part of the style guide.

@vanniktech
Copy link
Contributor Author

Then ktlint shouldn't flag this, should it?

@NightlyNexus
Copy link
Contributor

i think it flags it because there should be only a single indent, not a special double indent.

@vanniktech
Copy link
Contributor Author

Should not ktlint support this though? At least when specifying the continuation_indent_size.

@NightlyNexus
Copy link
Contributor

Oh, I didn't realize there was a continuation indent size setting for ktlint. Seems like that should be removed, especially if it's not working.

@shashachu
Copy link
Contributor

Ah yeah it got effectively deprecated here #171 (release 0.22) so it should just be removed.

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

No branches or pull requests

3 participants