Skip to content

Commit

Permalink
Do not trigger optional_enum_case_matching on _?
Browse files Browse the repository at this point in the history
Fixes #3057
  • Loading branch information
marcelofabri committed Feb 8, 2020
1 parent bdede7b commit e75d393
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@

* Implicit_return description now reports current config correctly.
[John Buckley](https://github.com/nhojb)


* Do not trigger `optional_enum_case_matching` rule on `_?` as the `?` might
be required in some situations.
[Marcelo Fabri](https://github.com/marcelofabri)
[#3057](https://github.com/realm/SwiftLint/issues/3057)

## 0.38.2: Machine Repair Manual

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public struct OptionalEnumCaseMatchingRule: SubstitutionCorrectableASTRule, Conf
case (_, .baz): break
default: break
}
"""),
Example("""
switch (x, y) {
case (.c, _?):
break
case (.c, nil):
break
case (_, _):
break
}
""")
],
triggeringExamples: [
Expand Down Expand Up @@ -180,6 +190,9 @@ public struct OptionalEnumCaseMatchingRule: SubstitutionCorrectableASTRule, Conf
}

return tokensToCheck.compactMap { tokenToCheck in
guard !file.isTokenUnderscoreKeyword(tokenToCheck) else {
return nil
}
let questionMarkByteRange = ByteRange(location: tokenToCheck.range.upperBound, length: 1)
guard contents.substringWithByteRange(questionMarkByteRange) == "?" else {
return nil
Expand Down

0 comments on commit e75d393

Please sign in to comment.