SwiftLint
SwiftLint copied to clipboard
`unused-parameter` rule should not trigger on parameters used for their type
trafficstars
New Issue Checklist
- [x] I've Updated SwiftLint to the latest version.
- [x] I've searched for existing GitHub issues.
Bug Description
It should not report for cases where the parameter is used for its type and not value.
extension Data {
func jsonDecoded<T: Decodable>(ofType type: T.Type) throws -> T {
try JSONDecoder().decode(T.self, from: self)
}
}
Here the type parameter decides the return type.
Environment
- SwiftLint version: 0.56.0
- Xcode version: Xcode 15.4, Build version 15F31d
- Installation method used: Installer
- Configuration file:
only_rules:
- unused_parameter
The rule suggests to write it like:
extension Data {
func jsonDecoded<T: Decodable>(ofType _: T.Type) throws -> T {
try JSONDecoder().decode(T.self, from: self)
}
}
The intention is not to remove the parameter entirely if that's infeasible.
My argument is that the parameter is technically used when used for its type, not its value. My thinking is that, the parameter is used if removing the parameter makes the function no longer compile.