Unused Closure Parameter
Unused parameter in a closure should be replaced with _
- Identifier:
unused_closure_parameter
- Enabled by default: Yes
- Supports autocorrection: Yes
- Kind: lint
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning
Non Triggering Examples
[1, 2].map { $0 + 1 }
[1, 2].map({ $0 + 1 })
[1, 2].map { number in
number + 1
}
[1, 2].map { _ in
3
}
[1, 2].something { number, idx in
return number * idx
}
let isEmpty = [1, 2].isEmpty()
violations.sorted(by: { lhs, rhs in
return lhs.location > rhs.location
})
rlmConfiguration.migrationBlock.map { rlmMigration in
return { migration, schemaVersion in
rlmMigration(migration.rlmMigration, schemaVersion)
}
}
genericsFunc { (a: Type, b) in
a + b
}
var label: UILabel = { (lbl: UILabel) -> UILabel in
lbl.backgroundColor = .red
return lbl
}(UILabel())
hoge(arg: num) { num in
return num
}
({ (manager: FileManager) in
print(manager)
})(FileManager.default)
withPostSideEffect { input in
if true { print("\(input)") }
}
viewModel?.profileImage.didSet(weak: self) { (self, profileImage) in
self.profileImageView.image = profileImage
}
let failure: Failure = { task, error in
observer.sendFailed(error, task)
}
List($names) { $name in
Text(name)
}
List($names) { $name in
TextField($name)
}
_ = ["a"].filter { `class` in `class`.hasPrefix("a") }
let closure: (Int) -> Void = { `foo` in _ = foo }
let closure: (Int) -> Void = { foo in _ = `foo` }
Triggering Examples
[1, 2].map { ↓number in
return 3 }
[1, 2].map { ↓number in
return numberWithSuffix }
[1, 2].map { ↓number in
return 3 // number }
[1, 2].map { ↓number in
return 3 "number" }
[1, 2].something { number, ↓idx in
return number }
genericsFunc { (↓number: TypeA, idx: TypeB) in return idx }
let c: (Int) -> Void = { foo in _ = .foo }
hoge(arg: num) { ↓num in
}
fooFunc { ↓아 in }
func foo () {
bar { ↓number in return 3 }
viewModel?.profileImage.didSet(weak: self) { (↓self, profileImage) in
profileImageView.image = profileImage
}
let failure: Failure = { ↓task, error in
observer.sendFailed(error)
}
List($names) { ↓$name in
Text("Foo")
}
let class1 = "a"
_ = ["a"].filter { ↓`class` in `class1`.hasPrefix("a") }