-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functions w/ Only Multiple Trailing Closures Trigger "No Space in Method Call" (Swift 5.3) #3259
Comments
I am seeing this same issue, and getting two warnings:
|
@ohayon I assumed the "Multiple Closures with Trailing Closure" to be working correctly in detecting multiple closures when a trailing closure is used, and that it could be disabled now. However, it could be modified to detect multiple trailing closures instead. This way, it won't trigger on: Button {
print("Tapped")
} label: {
Text("Button")
} But will trigger on the current violation: Button(action: {
print("Tapped")
}) {
Text("Button")
} And trigger on a three-closure parameters function not using three trailing closure: myMethod(param1: { "closure1" }) {
"closure 2"
} param3: {
"closure 3"
} I'm playing around with the SourceKit params for structures to understand how some of the current rules around these are implemented, then learn how to determine when a closure is a proper trailing closure. |
@giladronat Can you open another issue to discuss |
Wow fantastic work @marcelofabri, thank you. Yes, will gladly open another issue to discuss Regarding #3280, if you have a moment, could you explain how the initial closure's body offset matching the body offset of the function call determines it's the beginning of trailing closures (this line)? I'll admit I spent far too long trying to understand what differentiates a trailing closure from non-trailing closures and unnamed closure arguments in order to PR a fix I knew accounted for this case without breaking others. For example, looking at TrailingClosureRule and MultipleClosuresWithTrailingClosures gave me the impression the solution would be more involved. |
Opened #3295 to discuss |
New Issue Checklist
Describe the bug
When using Swift 5.3's multiple trailing closure syntax (disabling the rule for
multiple_closures_with_trailing_closure
), a function call with only multiple trailing closures as arguments will trigger "No Space in Method Call Violation."Common examples of such functions are:
sink
Operator:Function calls that begin with non-closure parameters followed by multiple trailing closures work just fine. For example:
Removing the space properly triggers "Opening Brace Spacing Violation" (see
swiftlint autocorrect
output below).Complete output when running SwiftLint, including the stack trace and command used
Environment
swiftlint version
to be sure)?0.39.2
Homebrew
No.
xcodebuild -version
)?Xcode 12.0
Build version 12A6159
(Beta 1)
Additional Comments
Looking into fixing this by adjusting NoSpaceInMethodCallRule.swift. Once the issue is resolved, it may be worth considering disabling the
multiple_closures_with_trailing_closure
rule by default. While the new syntax isn't universally loved, it mitigates the call site ambiguity that motivated the rule's creation.The text was updated successfully, but these errors were encountered: