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

Error: NoMethodError has occurred in Style/TrailingCommaInBlockArgs cop #7841

Closed
yujideveloper opened this issue Apr 2, 2020 · 0 comments · Fixed by #7843
Closed

Error: NoMethodError has occurred in Style/TrailingCommaInBlockArgs cop #7841

yujideveloper opened this issue Apr 2, 2020 · 0 comments · Fixed by #7843
Labels

Comments

@yujideveloper
Copy link
Contributor

Expected behavior

NoMethodError is not occurred.

$ echo '-> (v1, v2) { puts v1 + v2 }' | rubocop --stdin foo.rb --only Style/TrailingCommaInBlockArgs
Inspecting 1 file
.

1 file inspected, no offenses detected

Actual behavior

NoMethodError is occurred.

$ echo '-> (v1, v2) { puts v1 + v2 }' | rubocop --debug --stdin foo.rb --only Style/TrailingCommaInBlockArgs
For /home/yujideveloper: configuration from /home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/config/default.yml
Inspecting 1 file
Scanning /home/yujideveloper/foo.rb
An error occurred while Style/TrailingCommaInBlockArgs cop was inspecting /home/yujideveloper/foo.rb:1:0.
undefined method `+' for nil:NilClass
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/style/trailing_comma_in_block_args.rb:80:in `argument_tokens'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/style/trailing_comma_in_block_args.rb:67:in `trailing_comma?'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/style/trailing_comma_in_block_args.rb:59:in `useless_trailing_comma?'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/style/trailing_comma_in_block_args.rb:47:in `on_block'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/commissioner.rb:57:in `block (2 levels) in trigger_responding_cops'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/commissioner.rb:136:in `with_cop_error_handling'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/commissioner.rb:56:in `block in trigger_responding_cops'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/commissioner.rb:55:in `each'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/commissioner.rb:55:in `trigger_responding_cops'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/commissioner.rb:32:in `block (2 levels) in <class:Commissioner>'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/ast/traversal.rb:14:in `walk'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/commissioner.rb:44:in `investigate'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/team.rb:124:in `investigate'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/team.rb:112:in `offenses'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:296:in `inspect_file'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:244:in `block in do_inspection_loop'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:276:in `block in iterate_until_no_changes'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:269:in `loop'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:269:in `iterate_until_no_changes'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:240:in `do_inspection_loop'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:119:in `block in file_offenses'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:143:in `file_offense_cache'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:117:in `file_offenses'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:108:in `process_file'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:87:in `block in each_inspected_file'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:86:in `each'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:86:in `reduce'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:73:in `inspect_files'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/runner.rb:39:in `run'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cli/command.rb:10:in `run'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cli/environment.rb:17:in `run'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cli.rb:65:in `run_command'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cli.rb:72:in `execute_runners'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/lib/rubocop/cli.rb:41:in `run'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/exe/rubocop:13:in `block in <top (required)>'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/home/yujideveloper/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/rubocop-0.81.0/exe/rubocop:12:in `<top (required)>'
/home/yujideveloper/.rbenv/versions/2.5.7/bin/rubocop:23:in `load'
/home/yujideveloper/.rbenv/versions/2.5.7/bin/rubocop:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Style/TrailingCommaInBlockArgs cop was inspecting /home/yujideveloper/foo.rb:1:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.81.0 (using Parser 2.7.0.5, running on ruby 2.5.7 x86_64-linux)
Finished in 0.26879936900149914 seconds

Steps to reproduce the problem

$ echo '-> (v1, v2) { puts v1 + v2 }' | rubocop --debug --stdin foo.rb --only Style/TrailingCommaInBlockArgs

RuboCop version

$ rubocop -V
0.81.0 (using Parser 2.7.0.5, running on ruby 2.5.7 x86_64-linux)
@koic koic added the bug label Apr 2, 2020
koic added a commit to koic/rubocop that referenced this issue Apr 4, 2020
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 closed this as completed in #7843 Apr 4, 2020
koic added a commit that referenced this issue Apr 4, 2020
…_in_block_args

[Fix #7841] Fix an error for `Style/TrailingCommaInBlockArgs` cop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants