@@ -11,7 +11,6 @@ struct VoidFunctionInTernaryConditionRule: Rule {
1111 kind: . idiomatic,
1212 minSwiftVersion: . fiveDotOne,
1313 nonTriggeringExamples: [
14- Example ( " let result = success ? foo() : bar() " ) ,
1514 Example ( """
1615 if success {
1716 askQuestion()
@@ -60,6 +59,14 @@ struct VoidFunctionInTernaryConditionRule: Rule {
6059 subscript(index: Int) -> Int {
6160 index == 0 ? defaultValue() : compute(index)
6261 """ ) ,
62+ Example ( """
63+ var a = b ? c() : d()
64+ a += b ? c() : d()
65+ a -= b ? c() : d()
66+ a *= b ? c() : d()
67+ a &<<= b ? c() : d()
68+ a &-= b ? c() : d()
69+ """ ) ,
6370 ] ,
6471 triggeringExamples: [
6572 Example ( " success ↓? askQuestion() : exit() " ) ,
@@ -144,18 +151,43 @@ private extension VoidFunctionInTernaryConditionRule {
144151
145152private extension ExprListSyntax {
146153 var containsAssignment : Bool {
147- children ( viewMode: . sourceAccurate) . contains ( where: { $0. is ( AssignmentExprSyntax . self) } )
154+ children ( viewMode: . sourceAccurate) . contains {
155+ if let binOp = $0. as ( BinaryOperatorExprSyntax . self) {
156+ // https://developer.apple.com/documentation/swift/operator-declarations
157+ return [
158+ " *= " ,
159+ " /= " ,
160+ " %= " ,
161+ " += " ,
162+ " -= " ,
163+ " <<= " ,
164+ " >>= " ,
165+ " &= " ,
166+ " |= " ,
167+ " ^= " ,
168+ " &*= " ,
169+ " &+= " ,
170+ " &-= " ,
171+ " &<<= " ,
172+ " &>>= " ,
173+ " .&= " ,
174+ " .|= " ,
175+ " .^= " ,
176+ ] . contains ( binOp. operator. text)
177+ }
178+ return $0. is ( AssignmentExprSyntax . self)
179+ }
148180 }
149181}
150182
151183private extension CodeBlockItemSyntax {
152184 var isImplicitReturn : Bool {
153- isClosureImplictReturn || isFunctionImplicitReturn ||
185+ isClosureImplicitReturn || isFunctionImplicitReturn ||
154186 isVariableImplicitReturn || isSubscriptImplicitReturn ||
155- isAcessorImplicitReturn
187+ isAccessorImplicitReturn
156188 }
157189
158- var isClosureImplictReturn : Bool {
190+ var isClosureImplicitReturn : Bool {
159191 guard let parent = parent? . as ( CodeBlockItemListSyntax . self) ,
160192 let grandparent = parent. parent else {
161193 return false
@@ -191,7 +223,7 @@ private extension CodeBlockItemSyntax {
191223 return parent. children ( viewMode: . sourceAccurate) . count == 1 && subscriptDecl. allowsImplicitReturns
192224 }
193225
194- var isAcessorImplicitReturn : Bool {
226+ var isAccessorImplicitReturn : Bool {
195227 guard let parent = parent? . as ( CodeBlockItemListSyntax . self) ,
196228 parent. parent? . parent? . as ( AccessorDeclSyntax . self) != nil else {
197229 return false
0 commit comments