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

Comments

Projects
None yet
4 participants
@astorije
Contributor

astorije commented Oct 16, 2016

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

This comment has been minimized.

Show comment
Hide comment
@bbatsov

bbatsov Oct 16, 2016

Collaborator

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.

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

This comment has been minimized.

Show comment
Hide comment
@savef

savef Oct 17, 2016

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@bbatsov

bbatsov Oct 18, 2016

Collaborator

Fine by me.

Collaborator

bbatsov commented Oct 18, 2016

Fine by me.

@swcraig

This comment has been minimized.

Show comment
Hide comment
@swcraig

swcraig Oct 20, 2016

Contributor

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

Contributor

swcraig commented Oct 20, 2016

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

swcraig added a commit to swcraig/rubocop that referenced this issue Oct 20, 2016

swcraig added a commit to swcraig/rubocop that referenced this issue Oct 20, 2016

swcraig added a commit to swcraig/rubocop that referenced this issue Oct 21, 2016

swcraig added a commit to swcraig/rubocop that referenced this issue Oct 21, 2016

swcraig added a commit to swcraig/rubocop that referenced this issue Oct 21, 2016

swcraig added a commit to swcraig/rubocop that referenced this issue Oct 21, 2016

swcraig added a commit to swcraig/rubocop that referenced this issue Oct 22, 2016

@bbatsov bbatsov closed this in a94bef0 Oct 24, 2016

b-t-g pushed a commit to b-t-g/rubocop that referenced this issue Oct 29, 2016

legendetm added a commit to legendetm/rubocop that referenced this issue Nov 1, 2016

Merge remote-tracking branch 'main/master' into empty_lines_special
* main/master: (42 commits)
  [Fix rubocop-hq#3662] Remove brackets from an array literal being expanded in another array
  Add forgotten update the manual
  Cut 0.45
  [Fix rubocop-hq#3676] Ignore invocations of raw and html_safe when safe_join is used (rubocop-hq#3682)
  Fix option name in HashSyntax's documentation (rubocop-hq#3683)
  Bump default Ruby version to 2.1
  Add new `Lint/EmptyExpression` cop
  Improve the performance of `Style/ExtraSpacing` cop
  [Fix rubocop-hq#3631] Add new `Style/SpaceInLambdaLiteral` cop
  Use `const_get` instead of `eval` to get an exception
  [Fix rubocop-hq#3494] Check rails indentation inside blocks in IndentationWidth
  Fix bug in `Lint/EmptyWhen` with empty condition
  [rubocop-hq#3650] Fix the checks for variables in VariableNumber
  [Fix rubocop-hq#3553] Make Style/RedundantSelf accept self.()
  Fix false positive for Rails/SafeNavigation when without receiver
  Fix bug in SafeNavigation where an elsif branch mimics an if branch
  [Fix rubocop-hq#3647] Add --force-default-config option
  Add more keywords for Rails/HttpPositionalArguments
  [Fix rubocop-hq#3652] Avoid crash Rails/HttpPositionalArguments for lvar params when auto-correct
  Move a changelog entry
  ...

legendetm added a commit to legendetm/rubocop that referenced this issue Nov 1, 2016

Merge remote-tracking branch 'main/master' into empty_lines_special
* main/master: (42 commits)
  [Fix rubocop-hq#3662] Remove brackets from an array literal being expanded in another array
  Add forgotten update the manual
  Cut 0.45
  [Fix rubocop-hq#3676] Ignore invocations of raw and html_safe when safe_join is used (rubocop-hq#3682)
  Fix option name in HashSyntax's documentation (rubocop-hq#3683)
  Bump default Ruby version to 2.1
  Add new `Lint/EmptyExpression` cop
  Improve the performance of `Style/ExtraSpacing` cop
  [Fix rubocop-hq#3631] Add new `Style/SpaceInLambdaLiteral` cop
  Use `const_get` instead of `eval` to get an exception
  [Fix rubocop-hq#3494] Check rails indentation inside blocks in IndentationWidth
  Fix bug in `Lint/EmptyWhen` with empty condition
  [rubocop-hq#3650] Fix the checks for variables in VariableNumber
  [Fix rubocop-hq#3553] Make Style/RedundantSelf accept self.()
  Fix false positive for Rails/SafeNavigation when without receiver
  Fix bug in SafeNavigation where an elsif branch mimics an if branch
  [Fix rubocop-hq#3647] Add --force-default-config option
  Add more keywords for Rails/HttpPositionalArguments
  [Fix rubocop-hq#3652] Avoid crash Rails/HttpPositionalArguments for lvar params when auto-correct
  Move a changelog entry
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment