Function Parameter Count

Number of function parameters should be low.

  • Identifier: function_parameter_count
  • Enabled by default: Yes
  • Supports autocorrection: No
  • Kind: metrics
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    warning 5
    error 8
    ignores_default_parameters true

Non Triggering Examples

init(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
init (a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
`init`(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
init?(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
init?<T>(a: T, b: Int, c: Int, d: Int, e: Int, f: Int) {}
init?<T: String>(a: T, b: Int, c: Int, d: Int, e: Int, f: Int) {}
func f2(p1: Int, p2: Int) { }
func f(a: Int, b: Int, c: Int, d: Int, x: Int = 42) {}
func f(a: [Int], b: Int, c: Int, d: Int, f: Int) -> [Int] {
    let s = a.flatMap { $0 as? [String: Int] } ?? []}}
override func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}

Triggering Examples

func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
func initialValue(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
private func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int = 2, g: Int) {}
struct Foo {
    init(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
    func bar(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}}