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

ktlint formatter removes indentation when it should not #1138

Closed
alz-ahm opened this issue Apr 26, 2021 · 4 comments
Closed

ktlint formatter removes indentation when it should not #1138

alz-ahm opened this issue Apr 26, 2021 · 4 comments

Comments

@alz-ahm
Copy link

alz-ahm commented Apr 26, 2021

Here is the originial and formatted code by ktlint 0.41.0. I renamed stuff here since I can not share the actual company code.
Original code:

object CardModule {
    @Provides
    fun provideCardComponent(
        myConsumer: Consumer,
        listener: MyListener
    ): CardComponent<
        MyCard.Info,
        MyCard.Events,
        MyCard.Configuration> {
        return CardComponent(
            param1,
            param2,
            param3,
            param4
        )
    }

Formatted code:

object CardModule {
    @Provides
    fun provideCardComponent(
    myConsumer: Consumer,
    listener: MyListener
): CardComponent<
        MyCard.Info,
        MyCard.Events,
        MyCard.Configuration> {
        return CardComponent(
            param1,
            param2,
            param3,
            param4
        )
    }

Expected Behavior

The indentation for ): CardComponent< line should not be removed. Also AS formats it correctly. If I run AS formatter on the code which is already formatted by ktlint, it will bring the indentation back and correct it.

Observed Behavior

As posted in the code, the indentation is removed where is should not.

Steps to reproduce

Run ktlint on the original code! I din't tried it on separate file though

Your Environment

  • Version of ktlint used: 0.41.0
  • Gradle plugin: 10.0.0
  • Version of Gradle used (if applicable): 7.0
  • Operating System and version: Mac Os Big Sur
@paul-dingemans
Copy link
Collaborator

In december 2020 I have prepared several Pull Requests which fixes a lot of indentation problems. The first one (#1052) of a series of 5 PR's or so however is still not merged. :-(

@paul-dingemans
Copy link
Collaborator

Just had another look at this issue. This is not an issue caused by the IndentationRule but a false negative of the ParameterListWrappingRule. I think it is a design flaw that rules other than the IndentationRule are trying to fix/report indentation errors given their context only.

@paul-dingemans
Copy link
Collaborator

The problem can not be reproduced in version 0.43.2. Output is now:

object CardModule {
    @Provides
    fun provideCardComponent(
        myConsumer: Consumer,
        listener: MyListener,
    ): CardComponent<
        MyCard.Info,
        MyCard.Events,
        MyCard.Configuration> {
        return CardComponent(
            param1,
            param2,
            param3,
            param4
        )
    }
}

@alzahm (cc @romtsn) Please confirm and close the issue.

@paul-dingemans
Copy link
Collaborator

Closing issue as no response was received in last month.

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

2 participants