Unused Parameter

Other than unused local variable declarations, unused function/initializer/subscript parameters are not marked by the Swift compiler. Since unused parameters are code smells, they should either be removed or replaced/shadowed by a wildcard ‘_’ to indicate that they are being deliberately disregarded.

  • Identifier: unused_parameter
  • Enabled by default: No
  • Supports autocorrection: Yes
  • Kind: lint
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

func f(a: Int) {
    _ = a
}
func f(case: Int) {
    _ = `case`
}
func f(a _: Int) {}
func f(_: Int) {}
func f(a: Int, b c: String) {
    func g() {
        _ = a
        _ = c
    }
}
func f(a: Int, c: Int) -> Int {
    struct S {
        let b = 1
        func f(a: Int, b: Int = 2) -> Int { a + b }
    }
    return a + c
}
func f(a: Int?) {
    if let a {}
}
func f(a: Int) {
    let a = a
    return a
}
func f(`operator`: Int) -> Int { `operator` }

Triggering Examples

func f(a: Int) {}
func f(a: Int, b c: String) {}
func f(a: Int, b c: String) {
    func g(a: Int, b: Double) {
        _ = a
    }
}
struct S {
    let a: Int

    init(a: Int, b: Int) {
        func f(a: Int, b: Int) -> Int { b }
        self.a = f(a: a, b: 0)
    }
}
struct S {
    subscript(a: Int, b: Int) {
        func f(a: Int, b: Int) -> Int { b }
        return f(a: a, b: 0)
    }
}
func f(a: Int, b: Int, c: Int) -> Int {
    struct S {
        let b = 1
        func f(a: Int, c: Int = 2) -> Int { a + b }
    }
    return S().f(a: c)
}
func f(a: Int, c: String) {
    let a = 1
    return a + c
}