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 expressions on newline #1154

Closed
meesec opened this issue May 25, 2021 · 5 comments
Closed

indentation for expressions on newline #1154

meesec opened this issue May 25, 2021 · 5 comments

Comments

@meesec
Copy link

meesec commented May 25, 2021

Expected Behavior

This should not trigger any rules (and is correct in 0.39.0):

operator fun x(resources: Resources, entity: X):
    ListItem<SomeClass> =
        foo(
            resources = resources,
            ...
        )

Observed Behavior (in 0.41.0)

operator fun x(resources: Resources, entity: X):
    ListItem<SomeClass> =
    foo(
        resources = resources,
        ...
    )

Steps to Reproduce

the same can be observed for

foo()
List<Sth> = map {
    when (it.a) {
        a.b -> c
        else -> it
    }
}
bar()
foo()
positiveButtonText =
    R.string.my_long_res_name_that_forces_a_linebreak_string
bar()

Your Environment

  • Version of ktlint used: upgrade to 0.41.0 (used to work in 0.39.0)
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): plain ktlint on cmd
  • Version of Gradle used (if applicable):
  • Operating System and version: any
  • Link to your project (if it's a public repository): sry
@vojkny
Copy link

vojkny commented Jun 28, 2021

I confirm this incorrect behaviour in 0.41.0

@paul-dingemans
Copy link
Collaborator

This issue will be solved by #1341. Note that code sample given in this issue do not adhere to the coding guideline and should be rewritten as documented in previously mentioned issue.

@paul-dingemans
Copy link
Collaborator

operator fun x(resources: Resources, entity: X):
    ListItem<SomeClass> =
        foo(
            resources = resources,
            ...
        )

The experimental:function-signature rules which was released in 0.46.x is able to rewrite the examples above in accordance to the Kotlin Coding conventions and Android Kotlin Style guide. The return type ListItem<SomeClass> and the closing parenthesis on the function should be on the same line. Once that is fixed, it is clear that the identation should be 4 instead of 8 characters.

The second example is ambiguous. If I interpret it as:

fun foobar() {
    foo()
    val something: List<Sth> = map {
        when (it.a) {
            a.b -> c
            else -> it
        }
    }
    bar()
}

then its formatting is correct.

Same for third example:

fun foobar() {
    foo()
    positiveButtonText =
        R.string.my_long_res_name_that_forces_a_linebreak_string
    bar()
}

Please let me know if I misinterpreted the last two examples and provide some real working code snippets which demonstrate the problems.

@paul-dingemans
Copy link
Collaborator

Original problem is also mentioned in #1217. As that issue contains more context and discussion, this issue is closed in favour of #1217. For second and third problem no feedback has been received since July 6th, 2022.

@paul-dingemans
Copy link
Collaborator

And now actually closing the issue.

@paul-dingemans paul-dingemans closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants