Taint branches of tainted ternary expressions (#6393)

This commit is contained in:
Danny Mösch
2025-12-26 22:49:21 +01:00
committed by GitHub
parent 0c7eb017e2
commit c09e3bbe34
2 changed files with 12 additions and 1 deletions
+4 -1
View File
@@ -19,7 +19,10 @@
### Bug Fixes
* None.
* Treat closures in the branches of ternary expressions as escaping
when the whole expression is escaping in the `unneeded_escaping` rule.
[SimplyDanny](https://github.com/SimplyDanny)
[#6386](https://github.com/realm/SwiftLint/pull/6386)
## 0.63.0-rc.2: High-Speed Extraction
@@ -102,6 +102,11 @@ struct UnneededEscapingRule: Rule {
var cs = [1: c]
}
""", excludeFromDocumentation: true),
Example("""
func f(c: @escaping () -> Void) {
f(true ? c : { })
}
"""),
],
triggeringExamples: [
Example("""
@@ -324,6 +329,9 @@ private final class EscapeChecker: SyntaxVisitor {
let declRef = optChain.expression.as(DeclReferenceExprSyntax.self) {
return taintedVariables.contains(declRef.baseName.text)
}
if let ternary = expr.as(TernaryExprSyntax.self) {
return isTainted(ternary.thenExpression) || isTainted(ternary.elseExpression)
}
return false
}
}