Fix false positive when result is accessed (#4986)
This commit is contained in:
parent
7f3b93147a
commit
87e230ce87
|
@ -21,6 +21,10 @@
|
|||
[SimplyDanny](https://github.com/SimplyDanny)
|
||||
[#2180](https://github.com/realm/SwiftLint/issues/2180)
|
||||
|
||||
* Fixed a false positive in `unhandled_throwing_task`.
|
||||
[kylebshr](https://github.com/kylebshr)
|
||||
[#4984](https://github.com/realm/SwiftLint/issues/4984)
|
||||
|
||||
## 0.52.0: Crisp Clear Pleats
|
||||
|
||||
#### Breaking
|
||||
|
|
|
@ -77,6 +77,11 @@ struct UnhandledThrowingTaskRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
|||
executor.task = Task {
|
||||
try await isolatedOpen(.init(executor.asUnownedSerialExecutor()))
|
||||
}
|
||||
"""),
|
||||
Example("""
|
||||
let result = await Task {
|
||||
throw CancellationError()
|
||||
}.result
|
||||
""")
|
||||
],
|
||||
triggeringExamples: [
|
||||
|
@ -169,7 +174,7 @@ private extension FunctionCallExprSyntax {
|
|||
var hasViolation: Bool {
|
||||
isTaskWithImplicitErrorType &&
|
||||
doesThrow &&
|
||||
!(isAssigned || isValueAccessed)
|
||||
!(isAssigned || isValueOrResultAccessed)
|
||||
}
|
||||
|
||||
var isTaskWithImplicitErrorType: Bool {
|
||||
|
@ -207,12 +212,12 @@ private extension FunctionCallExprSyntax {
|
|||
return false
|
||||
}
|
||||
|
||||
var isValueAccessed: Bool {
|
||||
var isValueOrResultAccessed: Bool {
|
||||
guard let parent = parent?.as(MemberAccessExprSyntax.self) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return parent.name.text == "value"
|
||||
return parent.name.text == "value" || parent.name.text == "result"
|
||||
}
|
||||
|
||||
var doesThrow: Bool {
|
||||
|
|
Loading…
Reference in New Issue