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: multiline_arguments: Allow enforcing only after first closure #1896

Closed
2 tasks done
ldiqual opened this issue Oct 11, 2017 · 5 comments
Closed
2 tasks done
Labels
rule-request Requests for a new rules.

Comments

@ldiqual
Copy link

ldiqual commented Oct 11, 2017

New Issue Checklist

Rule Request

My proposal is to add a new configuration for multiline_arguments that would allow enforcing the rule only after the first closure.

For instance, I would like to handle this case:

UIView.animate(withDuration: duration, animations: {
    // animations
}, completion: { _ in
    // completion
})

However with the current defaults, I have to write it this way:

UIView.animate(
    withDuration: duration,
    animations: {
        // animations
    }, completion: { _ in
        // completion
    }
)

You would also be able to pass more inline arguments before animations.

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.

I believe that the animate + completion case above is common across iOS codebases and that the first style above is a common way to express it.

Ray Wenderlich's swift style guide passes animations on the same line: https://github.com/raywenderlich/swift-style-guide#closure-expressions

  1. Provide several examples of what would and wouldn't trigger violations.

Doesn't trigger

call(a: a, b: {

}, c: {

})
call(a: a, b:b, c: {

}, d: {

})

Triggers

call(a: a, b:b,
  c: c, d: {

  }, d: {

  }
)
call(a: a, b: {

}, c: {

}, d: d, e: e)
  1. Should the rule be configurable, if so what parameters should be configurable?

A name for such option could be:

  • allow_first_closure_on_same_line
  • only_enforce_after_first_closure

Hard to describe the intent in a generic way and I'd love input from you guys.

  1. Should the rule be opt-in or enabled by default? Why?
    See README.md for guidelines on when to mark a
    rule as opt-in.

The option would be enabled by default for the multiline_arguments rule, since this is a common case as described above.

@ldiqual ldiqual changed the title multiline_arguments: Allow closure argument on same line multiline_arguments: Allow enforcing only after first closure Oct 11, 2017
@tinder-garricnahapetian

I think this is a great idea. Would it be hard to implement? I could give it a try. Where would I start?

@jpsim jpsim added the rule-request Requests for a new rules. label Nov 15, 2017
@jpsim jpsim changed the title multiline_arguments: Allow enforcing only after first closure Rule Request: multiline_arguments: Allow enforcing only after first closure Nov 15, 2017
@jpsim
Copy link
Collaborator

jpsim commented Nov 15, 2017

Shouldn't be too hard. Start in MultilineArgumentsRule.swift and MultilineArgumentsConfiguration.swift.

@hani-ibrahim
Copy link

any updates on this?

maciesielka added a commit to maciesielka/SwiftLint that referenced this issue Jul 5, 2018
maciesielka added a commit to maciesielka/SwiftLint that referenced this issue Jul 5, 2018
@maciesielka
Copy link
Contributor

Took a stab at adding this in #2281

@marcelofabri
Copy link
Collaborator

Implemented by @maciesielka in #2281 🎉

dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Aug 14, 2018
sjavora pushed a commit to sjavora/SwiftLint that referenced this issue Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

No branches or pull requests

6 participants