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

Add a cop to prevent -> ( lambda format #3631

Closed
astorije opened this issue Oct 16, 2016 · 4 comments
Closed

Add a cop to prevent -> ( lambda format #3631

astorije opened this issue Oct 16, 2016 · 4 comments

Comments

@astorije
Copy link
Contributor

As discovered in rmosolgo/graphql-ruby#313:

  • Both -> (arg) { ... } and ->(arg) { ... } are supported in Ruby 2+ (notice the space between -> and the parenthesis.
  • -> (arg) { ... } is not supported in Ruby 1.9.3 and the interpreter reports:
syntax error, unexpected tLPAREN_ARG, expecting keyword_do_LAMBDA or tLAMBEG (SyntaxError)
      -> (arg) {
          ^

It seems reasonable to me to enforce ->(arg) { ... } in style guides. After all, all examples in Rubocop's doc or your Ruby style guide use this format consistently.

This is very valuable when developing a library that supports both versions 1.9.3 and 2+.

Looking forward to hearing your opinion on that.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 16, 2016

While I don't care at all about 1.9.3 compatibility, I agree that we should stick to the style without a space for historical reasons. I have some memory that at one points we added some similar check to RuboCop, but I might be mistaken.

@savef
Copy link
Contributor

savef commented Oct 17, 2016

I like the idea of a cop to keep this consistent, but I would like the style to be configurable as I prefer the style with the space.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 18, 2016

Fine by me.

@swcraig
Copy link
Contributor

swcraig commented Oct 20, 2016

I have a working cop for this, and will commit soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants