swiftlint

Require multiline parameters and arguments to start on a new line after the opening parenthesis


I'm configuring SwiftLint for a project, and one of our standards that I would like to enforce is this: when a function is declared or called, and its parameters or arguments are broken over multiple lines, then the first parameter should always be on the line after the function name.

In other words, it should always look like this:

func foo(
  bar: Int,
  baz: Int
  ...

foo(
  bar: 0,
  baz: 1

and never like this:

func foo(bar: Int
         baz: Int
         ...

foo(bar: 0,
    baz: 1
    ...

I've looked for a rule like this in among the predefined rules, but I couldn't find one. I'm really hoping I just missed it, because this seems like a rule that could be auto-applied with --fix quite easily.

If no such rule exists, I suppose it wouldn't be too hard to create a custom rule, but then (to my understanding) setting it up to be auto-applied is out of the question. Or am I wrong?


Solution

  • I believe rules that you are looking for are:

    The first is responsible for function calls. The second is responsible for function declarations.