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

Multiline lambda parameters #54

Open
ctbarbour opened this issue Jan 22, 2020 · 5 comments
Open

Multiline lambda parameters #54

ctbarbour opened this issue Jan 22, 2020 · 5 comments
Labels

Comments

@ctbarbour
Copy link

According to the Code Convention documentation:

When declaring parameter names in a multiline lambda, put the names on the first line, followed by the arrow and the newline:

So the example should probably read:

class Test {
    fun tryAdd(a: Int?, b: Int?): Int? {
        var result: Int? = null
        a?.let { lhs ->
            b?.let { rhs ->
                result = lhs + rhs
            }
        }
        return result
    }
}

However, when putting parameters on the first line Kotlin-mode will indent the next line as follows:

class Test {                                                                                                                                                                             
    fun tryAdd(a: Int?, b: Int?): Int? {                                                                                                                                                 
        var result: Int? = null                                                                                                                                                          
        a?.let { lhs ->                                                                                                                                                                  
                     b?.let { rhs ->                                                                                                                                                     
                                  result = lhs + rhs                                                                                                                                     
                     }                                                                                                                                                                   
        }                                                                                                                                                                                
        return result                                                                                                                                                                    
    }                                                                                                                                                                                    
}

Further when adding normal declarations like variable assignment the first line is indented further than the remaining lines in the lambda:

class Test {                                                                                                                                                                             
    fun tryAdd(a: Int?, b: Int?): Int? {                                                                                                                                                 
        var result: Int? = null                                                                                                                                                          
        a?.let { lhs ->                                                                                                                                                                  
                     val test = "variable assignment"                                                                                                                                    
                 val anotherVariable = "another"                                                                                                                                         
                 b?.let { rhs ->                                                                                                                                                         
                              result = lhs + rhs                                                                                                                                         
                 }                                                                                                                                                                       
        }                                                                                                                                                                                
        return result                                                                                                                                                                    
    }                                                                                                                                                                                    
}
@taku0
Copy link
Contributor

taku0 commented Jan 22, 2020

#53 will fix this.

class Test {
    fun tryAdd(a: Int?, b: Int?): Int? {
        var result: Int? = null
        a?.let { lhs ->
            b?.let { rhs ->
                result = lhs + rhs
            }
        }
        return result
    }
}
class Test {
    fun tryAdd(a: Int?, b: Int?): Int? {
        var result: Int? = null
        a?.let { lhs ->
            val test = "variable assignment"
            val anotherVariable = "another"
            b?.let { rhs ->
                result = lhs + rhs
            }
        }
        return result
    }
}
foo {
    context: Context,
    environment: Env
    ->
    context.configureEnv(environment)
}

foo { context: Context, // Non-standard style
      environment: Env
      ->
    context.configureEnv(environment)
}

@ctbarbour
Copy link
Author

I'll give that a try. Thanks!

@rudolf-adamkovic
Copy link

This still does not work, does it?

assets.open(name).use { source ->
                            // indents here
}

Please reopen. #53 seems to have stalled.

@gregghz gregghz reopened this Jun 8, 2022
@gregghz gregghz added the bug label Jun 8, 2022
@bricka
Copy link
Contributor

bricka commented Dec 2, 2022

I was also annoyed by this and have an MR up to fix it: #73

@taku0
Copy link
Contributor

taku0 commented Mar 21, 2023

Now fixed as #53 is merged.

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

No branches or pull requests

5 participants