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

Fix void_function_in_ternary incorrectly triggered with if statement #5674

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

u-abyss
Copy link
Contributor

@u-abyss u-abyss commented Jul 15, 2024

Fixes #5611

This PR corrects that VoidFunctionInTernaryConditionRule incorrectly triggered with if statement.
This new rule is triggered or not depending on the return type of the function.

@SwiftLintBot
Copy link

SwiftLintBot commented Jul 15, 2024

2 Warnings
⚠️ If this is a user-facing change, please include a CHANGELOG entry to credit yourself!
You can find it at CHANGELOG.md.
⚠️ This PR may need tests.
17 Messages
📖 Linting Aerial with this PR took 0.18s vs 0.15s on main (20% slower)
📖 Linting Alamofire with this PR took 0.15s vs 0.15s on main (0% slower)
📖 Linting Brave with this PR took 0.6s vs 0.62s on main (3% faster)
📖 Linting DuckDuckGo with this PR took 0.47s vs 0.48s on main (2% faster)
📖 Linting Firefox with this PR took 1.38s vs 1.39s on main (0% faster)
📖 Linting Kickstarter with this PR took 0.72s vs 0.72s on main (0% slower)
📖 Linting Moya with this PR took 0.11s vs 0.11s on main (0% slower)
📖 Linting NetNewsWire with this PR took 0.26s vs 0.26s on main (0% slower)
📖 Linting Nimble with this PR took 0.12s vs 0.12s on main (0% slower)
📖 Linting PocketCasts with this PR took 0.64s vs 0.64s on main (0% slower)
📖 Linting Quick with this PR took 0.1s vs 0.1s on main (0% slower)
📖 Linting Realm with this PR took 0.43s vs 0.41s on main (4% slower)
📖 Linting Sourcery with this PR took 0.26s vs 0.27s on main (3% faster)
📖 Linting Swift with this PR took 0.4s vs 0.39s on main (2% slower)
📖 Linting VLC with this PR took 0.18s vs 0.17s on main (5% slower)
📖 Linting Wire with this PR took 1.65s vs 1.64s on main (0% slower)
📖 Linting WordPress with this PR took 1.04s vs 1.07s on main (2% faster)

Here's an example of your CHANGELOG entry:

* Fix void_function_in_ternary incorrectly triggered with if statement.  
  [u-abyss](https://github.com/u-abyss)
  [#issue_number](https://github.com/realm/SwiftLint/issues/issue_number)

note: There are two invisible spaces after the entry's text.

Generated by 🚫 Danger

@u-abyss u-abyss changed the title fix: void_function_in_ternary incorrectly triggered with if statement Fix void_function_in_ternary incorrectly triggered with if statement Sep 10, 2024
@u-abyss u-abyss marked this pull request as ready for review September 10, 2024 10:58
Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks taking up the issue!

The current implementation is very specific to implicit returns. However, if and switch expression can also appear as variable initializers and they can be nested into each other. I don't think the current solution addresses these cases, does it?

isTrue ? defaultValue() : defaultValue()
} else {
"Default"
}
Copy link
Collaborator

@SimplyDanny SimplyDanny Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This misses a return, doesn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

void_function_in_ternary incorrectly triggered with if and switch expressions
3 participants