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

Indentation for enum entries with multi-line initializers is wrong #518

Closed
bethcutler opened this issue Jul 8, 2019 · 6 comments · Fixed by #530
Closed

Indentation for enum entries with multi-line initializers is wrong #518

bethcutler opened this issue Jul 8, 2019 · 6 comments · Fixed by #530
Labels
Milestone

Comments

@bethcutler
Copy link
Contributor

Example code, formatted as we would like it to be:

enum class Color(val displayName: String, val value: Int) {
  RED(
    displayName = "Red",
    value = 1
  ),
  BLUE(
    displayName = "Blue",
    value = 2
  );
}

In this case, we get "Unexpected indentation" errors on every line from 3 to 9 (expecting 2 less indentation). We are using 2-space indentation here.

If formatted instead so that the initializer arguments are on one line there are no errors:

enum class Color(val displayName: String, val value: Int) {
  RED(displayName = "Red", value = 1),
  BLUE(displayName = "Blue", value = 2);
}
@bethcutler
Copy link
Contributor Author

Slightly wrong in my previous comment, there is no error on line 6 (the "BLUE" entry). If formatted like this, there are no errors:

enum class Color(val displayName: String, val value: Int) {
  RED(
  displayName = "Red",
  value = 1
),
  BLUE(
  displayName = "Blue",
  value = 2
);
}

@AdamMc331
Copy link
Contributor

Has this been released yet? I updated to "0.34.2" but I'm still seeing KtLint format everything back one indentation: https://gist.github.com/AdamMc331/8c6a9ea40ba36803aef3993acfb1e7ce

@Tapchicoma
Copy link
Collaborator

Tapchicoma commented Sep 30, 2019

@AdamMc331 according to changelog it was released: https://github.com/pinterest/ktlint/blob/master/CHANGELOG.md#0342---2019-07-22

You need to enable experimental rules.

@AdamMc331
Copy link
Contributor

I have experimental rules on. I tried changing the KtLint verison number in the gradle plugin, but I wonder if I made a mistake there. I will double check, but I can also just upgrade to the fancy new 9.0.0 which targets the latest KtLint and maybe that will resolve my issue. :D

@Tapchicoma
Copy link
Collaborator

You can check used ktlint version by running:

$ ./gradlew dependencies --configuration ktlint

@AdamMc331
Copy link
Contributor

Can confirm this was user error, I made a mistake in my gradle file. So sorry! Thanks for checking in though.

orchestr7 pushed a commit to saveourtool/diktat that referenced this issue Jun 29, 2020
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.

4 participants