You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a rule request. I'm willing to implement this myself and send a PR, but before doing that I'd like to know if the rule is wanted or not. To explain the desired rule, I'd like to first post the custom rule we are already using in our projects:
closure_params_parantheses:
included: ".*.swift"regex: '\{\s*\([^):]+\)\s*in'name: "Unnecessary Closure Params Parantheses"message: "Don't use parantheses around non-typed parameters in a closure."severity: warning
I felt like this rule might be useful for other projects as well, which is why I'm posting it. What do you think about it? For us it helps a lot to prevent common issues and enforce a shared style.
Rationale
When writing closures in Xcode, the Xcode auto-completion tends to always add parantheses around the parameters. I think this is intended by Apple and I also think it makes sense to ensure people don't get confused, when they try to specify the type explicitly (e.g. because of generics) and the code doesn't compile any more due to missing parantheses. But in many cases (if the type is not explicitly specified via : Type) it is unnecessary in Swift to add parentheses. According to the rule to keep code clean and concise, the parentheses should be removed in such cases.
A few examples:
// ❌ not acceptable
URLSession.shared.dataTask(with: request, completionHandler:{(sessionData, _, error)in
// some code
}
// ✅ acceptable
URLSession.shared.dataTask(with: request, completionHandler:{ sessionData, _, error in
// some code
}
// ❌ not acceptable
viewsForEntries.forEach{(entry, view)in /* some code */ }
// ✅ acceptable
viewsForEntries.forEach{ entry, view in /* some code */ }
The text was updated successfully, but these errors were encountered:
This is a rule request. I'm willing to implement this myself and send a PR, but before doing that I'd like to know if the rule is wanted or not. To explain the desired rule, I'd like to first post the custom rule we are already using in our projects:
I felt like this rule might be useful for other projects as well, which is why I'm posting it. What do you think about it? For us it helps a lot to prevent common issues and enforce a shared style.
Rationale
When writing closures in Xcode, the Xcode auto-completion tends to always add parantheses around the parameters. I think this is intended by Apple and I also think it makes sense to ensure people don't get confused, when they try to specify the type explicitly (e.g. because of generics) and the code doesn't compile any more due to missing parantheses. But in many cases (if the type is not explicitly specified via
: Type
) it is unnecessary in Swift to add parentheses. According to the rule to keep code clean and concise, the parentheses should be removed in such cases.A few examples:
The text was updated successfully, but these errors were encountered: