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

[Fix #7841] Fix an error for Style/TrailingCommaInBlockArgs cop #7843

Merged

Conversation

koic
Copy link
Member

@koic koic commented Apr 2, 2020

Fixes #7841.

This PR fixes an error for Style/TrailingCommaInBlockArgs cop when lambda literal (->) has multiple arguments. It will not be checked in the case of lambda literal because lambda literal (->) never have a block arguments.

# Valid syntax
% ruby -ce '-> (foo, bar) { do_something(foo, bar) }'
Syntax OK

# Syntax error
% ruby -ce '-> { |foo| do_something }'
-e:1: syntax error, unexpected '|'
-> { |foo| do_something }
      ^

# Also syntax error
% ruby -ce '-> (foo, bar,) { do_something(foo, bar) }'
-e:1: syntax error, unexpected ')'
-> (foo, bar,) { do_something(foo, bar) }
              ^
-e:1: syntax error, unexpected '}', expecting end-of-input
r,) { do_something(foo, bar) }
                              ^

Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the fix_error_for_style_trailing_comma_in_block_args branch from 0c8b2ea to f65c0f3 Compare April 2, 2020 10:43
@@ -44,6 +44,9 @@ class TrailingCommaInBlockArgs < Cop
MSG = 'Useless trailing comma present in block arguments.'

def on_block(node)
# lambda literal (`->`) never have a block arguments.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never has block arguments

@koic koic force-pushed the fix_error_for_style_trailing_comma_in_block_args branch from f65c0f3 to b5e216c Compare April 4, 2020 11:06
Fixes rubocop#7841.

This PR fixes an error for `Style/TrailingCommaInBlockArgs` cop
when lambda literal (`->`) has multiple arguments.
It will not be checked in the case of lambda literal because
lambda literal (`->`) never have a block arguments.

```console
# Valid syntax
% ruby -ce '-> (foo, bar) { do_something(foo, bar) }'
Syntax OK

# Syntax error
% ruby -ce '-> { |foo| do_something }'
-e:1: syntax error, unexpected '|'
-> { |foo| do_something }
      ^

# Also syntax error
% ruby -ce '-> (foo, bar,) { do_something(foo, bar) }'
-e:1: syntax error, unexpected ')'
-> (foo, bar,) { do_something(foo, bar) }
              ^
-e:1: syntax error, unexpected '}', expecting end-of-input
r,) { do_something(foo, bar) }
                              ^
```
@koic koic force-pushed the fix_error_for_style_trailing_comma_in_block_args branch from b5e216c to 6169ce3 Compare April 4, 2020 15:13
@koic koic merged commit 28f18ac into rubocop:master Apr 4, 2020
@koic koic deleted the fix_error_for_style_trailing_comma_in_block_args branch April 4, 2020 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: NoMethodError has occurred in Style/TrailingCommaInBlockArgs cop
2 participants