Hi, is there a rule to check if all parameters are...
# detekt
a
Hi, is there a rule to check if all parameters are either on a single line or each on a separate line?
Copy code
// ok
val a  = A(a, b, c, d)
val a = A(
  a, b, c, d
)

// not ok
val a = A(
  a, b, c
  d
)
m
Looks like the
ArgumentListWrapping
might be what you are looking for: https://detekt.dev/docs/rules/formatting/#argumentlistwrapping
All arguments should be on the same line, or every argument should be on a separate line.
Note that you'll have to add the formatting rule set as described here: https://github.com/detekt/detekt?tab=readme-ov-file#adding-more-rule-sets
a
Hm ... seems, it only works with methods, but not with classes.
m
Are you looking to enforce it both on method signatures and calls?
a
Yes
I'd recommend adding the formatting rules as linked above and seeing if that suits you. I think these two rules should do it
a
Ok, thanks for pointing out on this rule. Seems it's enabled in my project, but for some reason it didn't catch style violations. Will try to figure out why.
Probably, that rule checks class/function signature declarations, not calls signature
m
One of them is for arguments, the other is for parameters, so they should cover everything.
a
Got it, but still ArgumentListWrapping only works with functions for me:
Copy code
// ArgumentsListWrapping rule swears on this
val a = myFunction(
  a, b,
  c
)

// ArgumentsListWrapping rule doesn't see this
val a = MyClass(
  a, b
  c
)
m
On my end it works as expected
a
Ok, seems it doesn't work in a specific case, when I initialize the global variable from init block :
Copy code
// This is detected
init {
  var a = A(
    a, b, c,
    d
  )
}

// But not this
var a

init {
  a = A(
    a, b, c,
    d
  )
}
m
Well, the highlighted 3 there is magicnumber, but nonetheless it does note the issue
a
@Matti MK could you please check the case I sent above, if it works for you
m
Include the A class also
a
I didn't have a minimum reproducible example, I couldn't show the real classes. Probably I will setup a sandbox, prepare the example and come back to you.
m
I wanted to test it out and you are correct
Copy code
data class A(
    val a: Int, val b: Int, val c: Int, val d: Int
)

var a: A = A(1, 2, 3, 4)

class MyClass {
    init {
        val b = A(
            1, 2, 3,
            4
        )
    }

    init {
        a = A(
            1, 2, 3,
            4 // no ArgumentListWrapping here
        )
    }
}
a
Ok, then probably we need to report this.
m
Could be a good idea to create an issue. I don't think I'll have time to look into this anymore this week
a
Ok, then I'll open an issue. In this repository, right? https://github.com/detekt/detekt
m
Yes
a
Ok, thanks for assistance
👍 1