Skip to content

Commit

Permalink
fix: isIfExprImplicitReturn
Browse files Browse the repository at this point in the history
  • Loading branch information
u-abyss committed Sep 10, 2024
1 parent 7551964 commit 4dd6b3f
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ struct VoidFunctionInTernaryConditionRule: Rule {
}
"""),
Example("""
func exampleNestedIfExpr() -> String {
test()
if true {
isTrue ? defaultValue() : defaultValue()
} else {
"Default"
}
}
"""),
Example("""
func collectionView() -> CGSize {
switch indexPath.section {
case 0: isEditing ? CGSize(width: 150, height: 20) : CGSize(width: 100, height: 20)
Expand Down Expand Up @@ -262,7 +272,12 @@ private extension CodeBlockItemSyntax {
guard let funcDecl = ifExprSytax.parent?.parent?.parent?.parent?.parent?.as(FunctionDeclSyntax.self) else {
return false
}
return parent.children(viewMode: .sourceAccurate).count == 1 && funcDecl.signature.allowsImplicitReturns && ifExprSytax.parent?.parent?.parent?.as(CodeBlockItemListSyntax.self)?.count == 1
if let codeBlockItemListSyntax = ifExprSytax.parent?.parent?.parent?.as(CodeBlockItemListSyntax.self),
let expressionStmtSyntax = codeBlockItemListSyntax.last?.item.as(ExpressionStmtSyntax.self)
{
return parent.children(viewMode: .sourceAccurate).count == 1 && ( codeBlockItemListSyntax.count == 1 || expressionStmtSyntax.expression.is(IfExprSyntax.self)) && funcDecl.signature.allowsImplicitReturns
}
return false
}

var isSwitchExprImplicitReturn: Bool {
Expand Down

0 comments on commit 4dd6b3f

Please sign in to comment.