Skip to content
This repository has been archived by the owner on Oct 16, 2018. It is now read-only.

Clarify formatting for multi-line, single-argument method calls #68

Open
byencho opened this issue Jun 8, 2018 · 0 comments
Open

Clarify formatting for multi-line, single-argument method calls #68

byencho opened this issue Jun 8, 2018 · 0 comments

Comments

@byencho
Copy link

byencho commented Jun 8, 2018

The Kotlin language code style documentation makes clear that for multi-line, multi-argument method calls the arguments should appear on their own lines (potentially in groups):

drawSquare(
    x = 10, y = 10,
    width = 100, height = 100,
    fill = true
)

where ( ends the line it is on while the ) appears on its own line. The specific rule is

In long argument lists, put a line break after the opening parenthesis. Indent arguments by 4 spaces. Group multiple closely related arguments on the same line.

Is there any guidance for long method calls that wrap to multiple lines when there is only a single argument?

For example, are both the following correct?

setOnClickListener(object : View.OnClickListener {
    override fun onClick(v: View) {
        //...
     }
})

setOnClickListener(
        object : View.OnClickListener {
            override fun onClick(v: View) {
                //..
            }
         }
)

or is one preferred (ignoring for now that you'd just use a lambda here)? What if there is wrapping involved in the argument value itself? Are each of these valid:

someMethod(callsAVeryVeryLongFunctionWithHorribleName(
        andTonsAndTonsOfParameters,
        andMoreParameters
))

someMethod(
        callsAVeryVeryLongFunctionWithHorribleName(
                 andTonsAndTonsOfParameters,
                 andMoreParameters
        )
)
@byencho byencho changed the title Clarify formatting for multi-line, single argument method calls Clarify formatting for multi-line, single-argument method calls Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant