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

Split type arguments break 0.43.0 #1267

Closed
ZacSweers opened this issue Nov 2, 2021 · 5 comments · Fixed by #1284
Closed

Split type arguments break 0.43.0 #1267

ZacSweers opened this issue Nov 2, 2021 · 5 comments · Fixed by #1284

Comments

@ZacSweers
Copy link

ZacSweers commented Nov 2, 2021

Expected Behavior

I expect it to format it or accept it

Observed Behavior

It fails with an error like this

Step 'ktlint' found problem in 'path/to/file.kt':
Error on line: 48, column: 7
Unexpected indentation (expected 4, actual 6)
java.lang.AssertionError: Error on line: 48, column: 7
Unexpected indentation (expected 4, actual 6)
        at com.diffplug.spotless.kotlin.KtLintStep$State.lambda$createFormat$0(KtLintStep.java:129)
        at jdk.proxy49/jdk.proxy49.$Proxy441.invoke(Unknown Source)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:428)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:352)

Steps to Reproduce

this snippet fails for us

    fun setMessagingChannelDisplayNameMap(
      messagingChannelDisplayNameMap: Map<String, // This line
        String>
    ): Builder = apply {
      this.messagingChannelDisplayNameMap =
        messagingChannelDisplayNameMap
    }

Your Environment

  • Version of ktlint used: 0.43.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Spotless
  • Version of Gradle used (if applicable): N/A
  • Operating System and version: N/A
  • Link to your project (if it's a public repository): N/A
@paul-dingemans
Copy link
Collaborator

When I run ktlint --relative --verbose with the provide code sample, I get following output:

Issue1267.kt:1:1: Unexpected indentation (4) (should be 0) (indent)
Issue1267.kt:1:2: Unnecessary space(s) (no-multi-spaces)
Issue1267.kt:2:1: Unexpected indentation (6) (should be 4) (indent)
Issue1267.kt:2:7: Unexpected indentation (expected 4, actual 6) (parameter-list-wrapping)
Issue1267.kt:4:1: Unexpected indentation (4) (should be 0) (indent)
Issue1267.kt:4:5: Unexpected indentation (expected 0, actual 4) (parameter-list-wrapping)
Issue1267.kt:5:1: Unexpected indentation (6) (should be 4) (indent)
Issue1267.kt:7:1: Unexpected indentation (4) (should be 0) (indent)

Note that the output from rule parameter-list-wrapping should be considered as wrong as it conflicts with the indent rule.

With ktlint -F --relative --verbose, the ouput is as follows:

Issue1267.kt:1:1: Trailing space(s) (no-trailing-spaces)

and code is formatted like:

 
fun setMessagingChannelDisplayNameMap(
    messagingChannelDisplayNameMap: Map<String, // This line
        String>
): Builder = apply {
    this.messagingChannelDisplayNameMap =
        messagingChannelDisplayNameMap
}

Can you try to reproduce above on your system with a file only containing your code sample and nothing else in it? I have the idea that something else in the file initiate the error you reported.

@shashachu shashachu added the bug label Nov 4, 2021
@shashachu
Copy link
Contributor

@paul-dingemans we have a lot of rules touching the same code... I'm wondering if it's time to disable one or more of them so they stop conflicting with each other.

@paul-dingemans
Copy link
Collaborator

Yes, I really would prefer to do so. But in order to do so, we need this #1230 to be merged...

@ZacSweers
Copy link
Author

ZacSweers commented Nov 4, 2021

With the whole file, this is what it prints.

$ ./config/bin/ktlint -F --relative --verbose path/to/file.kt
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jetbrains.kotlin.com.intellij.util.ReflectionUtil (file:/Users/zsweers/dev/slack/restructure/slack-android-ng/config/bin/ktlint) to field java.lang.Throwable.backtrace
WARNING: Please consider reporting this to the maintainers of org.jetbrains.kotlin.com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
path/to/file.kt:48:7: Unexpected indentation (expected 4, actual 6) (parameter-list-wrapping)
path/to/file.kt:50:5: Unexpected indentation (expected 2, actual 4) (parameter-list-wrapping)

Where the line 48 is the line with the start of the generic type and line 50 is the line with the function return type. The error goes away if I put the type arguments on the same line.

With just that snippet alone, it has no errors.

@paul-dingemans
Copy link
Collaborator

Yes this is a known problem. The parameter list wrapping rule and the indent rule do not agree on the indent level. The indent rule however wins as it runs later. Those warnings of the parameter list wrapping rules can (should) be ignored

paul-dingemans pushed a commit to paul-dingemans/ktlint that referenced this issue Nov 10, 2021
Only the indentation rule should emit warnings about incorrect indentation to avoid
conflicting warnings from different rules about the indentation of the exact same
line. However, those other rules should still fix the indentation as good as they
can for the case that the indent rule is not run at all.

Closes pinterest#1267, pinterest#1119, pinterest#1045
@paul-dingemans paul-dingemans added this to the 0.44.0 milestone Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants