realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.46k stars 2.2k forks source link

Rule Request: Newline between function, array, dictionary, tuple parameters #5564

Closed kimdv closed 1 month ago

kimdv commented 1 month ago

New Issue Checklist

New rule request

After I read this proposal I tought it would be nice to have a rule like "if there is more than x parameters in a function/tuple/array/dictionary there must be a newline between".

This rule can also be implemented without this proposal implemented.

The reason for this is makes it easier to review code. So the rule should be opt-in. There could also be a configuration to state how many parameters there must be before newline is required.

It could also say that the trailing ) should be on a newline. We could also have a configuration that require the ( to have a trailing newline

Examples:

// Not OK
func foo(bar: Bar, baz: Baz)
func foo(
  bar: Bar,
  baz: Baz)

// OK
func foo(bar: Bar)
func foo(
  bar: Bar,
  baz: Baz
)

Not sure if it should be the same rule, but when calling a function we could also require newline.

Examples:

// Not OK
someClass.foo(bar: "bar", baz: "baz")
someClass.foo(
  bar: "bar",
  baz: "baz")

// OK
someClass.foo(bar: "bar")
someClass.foo(
  bar: "bar",
  baz: "baz"
)
kimdv commented 1 month ago

If it makes sense and it's a good idea I'm willing to try to implement it

kimdv commented 1 month ago

Is already in SwiftLint