Splitties icon indicating copy to clipboard operation
Splitties copied to clipboard

Add lint error when views are added in lParams lambda

Open LouisCAD opened this issue 7 years ago • 0 comments

Can you spot the error in the snippet below?

add(::verticalLayout, lParams(width = matchParent) {
    val inputLParams = lParams(width = matchParent)
    add(firstNameInput, inputLParams)
    add(lastNameInput, inputLParams)
    add(emailInput, inputLParams)
    add(mobilePhoneNumberInput, inputLParams)
})

Here's the fixed version:

add(::verticalLayout, lParams(width = matchParent)) {
    val inputLParams = lParams(width = matchParent)
    add(firstNameInput, inputLParams)
    add(lastNameInput, inputLParams)
    add(emailInput, inputLParams)
    add(mobilePhoneNumberInput, inputLParams)
}

Did you notice? I hopefully managed to notice my mistake. I added the views from the lParams lambda instead of from the add lambda, which made them be added to the parent of the verticalLayout instead of in the verticalLayout itself.

A lint should be able to catch such mistake and show an error

LouisCAD avatar Mar 23 '18 16:03 LouisCAD