@@ -21,7 +21,7 @@ struct YodaConditionRule: Rule {
21
21
Example ( " if foo == nil {} " ) ,
22
22
Example ( " if flags & 1 == 1 {} " ) ,
23
23
Example ( " if true {} " , excludeFromDocumentation: true ) ,
24
- Example ( " if true == false || b, 2 != 3, {} " , excludeFromDocumentation: true ) ,
24
+ Example ( " if true == false || b, 2 != 3 {} " , excludeFromDocumentation: true ) ,
25
25
] ,
26
26
triggeringExamples: [
27
27
Example ( " if ↓42 == foo {} " ) ,
@@ -72,20 +72,20 @@ private extension YodaConditionRule {
72
72
guard let operatorIndex = children. index ( of: comparisonOperator) else {
73
73
continue
74
74
}
75
- let rhsIdx = children. index ( operatorIndex , offsetBy : 1 )
75
+ let rhsIdx = children. index ( after : operatorIndex )
76
76
if children [ rhsIdx] . isLiteral {
77
- let afterRhsIndex = children. index ( after: rhsIdx)
78
- guard children. endIndex != rhsIdx, afterRhsIndex != nil else {
77
+ guard children. endIndex != children. index ( after: rhsIdx) else {
79
78
// This is already the end of the expression.
80
79
continue
81
80
}
81
+ let afterRhsIndex = children. index ( after: rhsIdx)
82
82
if children [ afterRhsIndex] . isLogicalBinaryOperator {
83
83
// Next token is an operator with weaker binding. Thus, the literal is unique on the
84
84
// right-hand side of the comparison operator.
85
85
continue
86
86
}
87
87
}
88
- let lhsIdx = children. index ( operatorIndex , offsetBy : - 1 )
88
+ let lhsIdx = children. index ( before : operatorIndex )
89
89
let lhs = children [ lhsIdx]
90
90
if lhs. isLiteral,
91
91
children. startIndex == lhsIdx || children [ children. index ( before: lhsIdx) ] . isLogicalBinaryOperator {
0 commit comments