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 19 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update
u-abyss committed Oct 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit be1efd1ce1499b9c383fcf06950a81924f1047e1
Original file line number Diff line number Diff line change
@@ -120,6 +120,14 @@ struct VoidFunctionInTernaryConditionRule: Rule {
}
}
"""),
Example("""
func collectionView() -> CGSize {
switch indexPath.section {
case 0: isEditing ? CGSize(width: 150, height: 20) : CGSize(width: 100, height: 20)
default: .zero
}
}
"""),
],
triggeringExamples: [
Example("success ↓? askQuestion() : exit()"),
@@ -382,17 +390,3 @@ private extension ReturnClauseSyntax {
return true
}
}

// Helper method that traces back the parent until a particular node reaches FunctionDeclSyntax.
private extension Syntax {
func findParent<T: SyntaxProtocol>(ofType _: T.Type) -> T? {
var current: Syntax? = self
while let parent = current?.parent {
if let parentNode = parent.as(T.self) {
return parentNode
}
current = parent
}
return nil
}
}