realm / realm/SwiftLint

void_function_in_ternary incorrectly triggered with if and switch expressions

Open
#5,611 3 comments 11 reactions 0 assignees View on GitHub

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
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.