Skip to content
New issue

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

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

Already on GitHub? # to your account

void_function_in_ternary incorrectly triggered with if and switch expressions #5611

Open
2 tasks done
tristanSIF opened this issue May 29, 2024 · 1 comment · May be fixed by #5674
Open
2 tasks done

void_function_in_ternary incorrectly triggered with if and switch expressions #5611

tristanSIF opened this issue May 29, 2024 · 1 comment · May be fixed by #5674
Labels
bug Unexpected and reproducible misbehavior.

Comments

@tristanSIF
Copy link

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
@SimplyDanny SimplyDanny added the bug Unexpected and reproducible misbehavior. label Jun 12, 2024
@mathieulb
Copy link

I second this, I have the problem with a function (x: MyEnum) -> String when using it in both sides of a ternary in a case. When I use the same function on only one side, the warning is not triggered. E.g.:

return switch {
  case 1: b ? f(.hello) : f(.world) // spurious warning
  case 2: b ? f(.hello) : "world" // OK
  case 3: b ? "hello" : f(.world) // OK
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants