Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused-parameter rule should not trigger on parameters used for their type #5742

Open
2 tasks done
sindresorhus opened this issue Aug 8, 2024 · 2 comments
Open
2 tasks done
Labels
discussion Topics that cannot be categorized as bugs or enhancements yet. They require further discussions.

Comments

@sindresorhus
Copy link

New Issue Checklist

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
@SimplyDanny
Copy link
Collaborator

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.

@SimplyDanny SimplyDanny added the discussion Topics that cannot be categorized as bugs or enhancements yet. They require further discussions. label Aug 10, 2024
@sindresorhus
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Topics that cannot be categorized as bugs or enhancements yet. They require further discussions.
Projects
None yet
Development

No branches or pull requests

2 participants