-
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
Rule Request: Multiple Closure Arguments with Trailing Closure #1801
Comments
This will conflict with the Xcode default style and must be manually added to the last parameter. |
For anyone searching for a non-triggering example of the animation with a completion:
Although as stated in the previous comment, this doesn't play nice with Xcode. |
me too |
Is there a way to turn off that Xcode default style? |
This is an annoying rule in SwiftUI |
Yeah this is a new permanent addition to my yml. I used to like the rule, but with SwiftUI I find it's nicer to use multiple trailing closures and cut down on a lot of the unnecessary wordiness. |
With SwiftUI, this has become a real pain to deal with and I'd rather ignore this rule |
You can always disable this rule in your configuration file. |
SwiftUI is an annoying rule :D in iOS. Sry xD |
New Issue Checklist
Rule Request
In many cases, the trailing closure syntax can make code clearer by reducing boilerplate. When passing a single closure argument to a function, that closure’s role is often clear even without its parameter label. When passing two closure arguments, however, the parameter labels crucially distinguish the role of the two closures. With trailing closure syntax, it becomes less clear that the second argument to
UIView.animate
is a completion handler:I propose a rule that would warn when the trailing closure syntax is used when passing two closure arguments to a function. The principle behind this rule is supported by the Ray Wenderlich Swift style guide and Erica Sadun’s blog post “Swift: The Problem with Trailing Closure Syntax”. SwiftLint’s existing Trailing Closure Rule already makes an exception when passing multiple closure arguments to a function (
foo.something(param1: { $0 }, param2: { $0 + 1 })
is a non-triggering example for that rule).The rule’s severity should be configurable to warning or error, defaulting to warning; there are no other obvious configurable parameters. The rule’s kind should be style. The rule should be enabled by default, because this style guideline has community support and generally improves code readability.
Additional examples of how this rule should behave:
Non-triggering examples:
Triggering examples:
The text was updated successfully, but these errors were encountered: