Skip to content

Commit de613ba

Browse files
authored
Prepare rule for SwiftSyntax 6.2 (#6144)
1 parent 929f0fc commit de613ba

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Source/SwiftLintBuiltInRules/Rules/Lint/YodaConditionRule.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct YodaConditionRule: Rule {
2121
Example("if foo == nil {}"),
2222
Example("if flags & 1 == 1 {}"),
2323
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),
2525
],
2626
triggeringExamples: [
2727
Example("if ↓42 == foo {}"),
@@ -72,20 +72,20 @@ private extension YodaConditionRule {
7272
guard let operatorIndex = children.index(of: comparisonOperator) else {
7373
continue
7474
}
75-
let rhsIdx = children.index(operatorIndex, offsetBy: 1)
75+
let rhsIdx = children.index(after: operatorIndex)
7676
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 {
7978
// This is already the end of the expression.
8079
continue
8180
}
81+
let afterRhsIndex = children.index(after: rhsIdx)
8282
if children[afterRhsIndex].isLogicalBinaryOperator {
8383
// Next token is an operator with weaker binding. Thus, the literal is unique on the
8484
// right-hand side of the comparison operator.
8585
continue
8686
}
8787
}
88-
let lhsIdx = children.index(operatorIndex, offsetBy: -1)
88+
let lhsIdx = children.index(before: operatorIndex)
8989
let lhs = children[lhsIdx]
9090
if lhs.isLiteral,
9191
children.startIndex == lhsIdx || children[children.index(before: lhsIdx)].isLogicalBinaryOperator {

0 commit comments

Comments
 (0)