Skip to content
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: Unnecessary Closure Params Parantheses #1633

Closed
Jeehut opened this issue Jun 20, 2017 · 2 comments
Closed

Rule Request: Unnecessary Closure Params Parantheses #1633

Jeehut opened this issue Jun 20, 2017 · 2 comments
Labels
duplicate Issues that already exist in other terms.

Comments

@Jeehut
Copy link
Collaborator

Jeehut commented Jun 20, 2017

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

Xcode always includes parentheses around parameters in closures, even when they are not typed. In these cases they are not needed though and therefore should be omitted.

A few examples:

// ❌ not acceptable
doSomething { (key, value) in
    // some code
}

// ✅ acceptable
doSomething { key, value in
    // some code
}
@Uncommon
Copy link
Contributor

What issues does it prevent? In my own code I've been preferring to always have the parens, but if they can cause problems maybe I should reconsider.

@marcelofabri
Copy link
Collaborator

Closing this as a duplicate of #1483. I was concerned about this rule because of the whole SE-0110 discussion, but it seems that is being reverted, so feel free to implement this.

What issues does it prevent? In my own code I've been preferring to always have the parens, but if they can cause problems maybe I should reconsider.

This is just a matter of style, removing extra clutter that is not needed (as parens in ifs for example).

@marcelofabri marcelofabri added the duplicate Issues that already exist in other terms. label Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues that already exist in other terms.
Projects
None yet
Development

No branches or pull requests

3 participants