void_function_in_ternary incorrectly triggered with if and switch expressions
Open
Nobody has claimed this yet.
bug
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
switch indexPath.section {
// Void Function in Ternary Violation: Using ternary to call Void functions should be avoided (void_function_in_ternary)
case 0: isEditing ? CGSize(width: 150, height: 20) : CGSize(width: 100, height: 20)
default: .zero
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.section == 0 {
// Void Function in Ternary Violation: Using ternary to call Void functions should be avoided (void_function_in_ternary)
isEditing ? CGSize(width: 150, height: 20) : CGSize(width: 100, height: 20)
} else {
.zero
}
}
### Environment
* SwiftLint version: 0.55.1
* Installation method used: Homebrew
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the examples with SwiftLint 0.55.1 and inspect the void_function_in_ternary rule. Done means the shown if and switch expressions no longer trigger the violation, with regression coverage for both forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100