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

Layout/BlockEndNewline causes undefined method `loc' for nil:NilClass #7791

Closed
gbp opened this issue Mar 10, 2020 · 0 comments · Fixed by #7792
Closed

Layout/BlockEndNewline causes undefined method `loc' for nil:NilClass #7791

gbp opened this issue Mar 10, 2020 · 0 comments · Fixed by #7792
Labels

Comments

@gbp
Copy link

gbp commented Mar 10, 2020

Expected behaviour

Expect no exception to be raised.

Actual behaviour

I get this error:

Inspecting 1 file
Scanning ~/test.rb
An error occurred while Layout/BlockEndNewline cop was inspecting ~/test.rb:1:0.
undefined method `loc' for nil:NilClass
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/layout/block_end_newline.rb:56:in `delimiter_range'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/layout/block_end_newline.rb:43:in `block in autocorrect'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/cop.rb:36:in `call'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/corrector.rb:63:in `block (2 levels) in rewrite'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/parser-2.7.0.4/lib/parser/source/tree_rewriter.rb:220:in `transaction'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/corrector.rb:62:in `block in rewrite'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/corrector.rb:60:in `each'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/corrector.rb:60:in `rewrite'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/team.rb:136:in `autocorrect_all_cops'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/team.rb:72:in `autocorrect'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/team.rb:108:in `block in offenses'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/team.rb:125:in `investigate'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/team.rb:104:in `offenses'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cop/team.rb:44:in `inspect_file'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:296:in `inspect_file'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:244:in `block in do_inspection_loop'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:276:in `block in iterate_until_no_changes'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:269:in `loop'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:269:in `iterate_until_no_changes'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:240:in `do_inspection_loop'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:119:in `block in file_offenses'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:143:in `file_offense_cache'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:117:in `file_offenses'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:108:in `process_file'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:87:in `block in each_inspected_file'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:86:in `each'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:86:in `reduce'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:86:in `each_inspected_file'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:73:in `inspect_files'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/runner.rb:39:in `run'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cli/command.rb:10:in `run'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cli/environment.rb:17:in `run'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cli.rb:65:in `run_command'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cli.rb:72:in `execute_runners'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop/cli.rb:41:in `run'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/exe/rubocop:13:in `block in <top (required)>'
~/rbenv/versions/2.6.5/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
~/rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/exe/rubocop:12:in `<top (required)>'
~/rbenv/versions/2.6.5/bin/rubocop:23:in `load'
~/rbenv/versions/2.6.5/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

Can be reproduced with:

foo {
  |bar| }

RuboCop version

$ rubocop -V
0.80.1 (using Parser 2.7.0.4, running on ruby 2.6.5 x86_64-darwin18)
@koic koic added the bug label Mar 11, 2020
koic added a commit to koic/rubocop that referenced this issue Mar 11, 2020
Fixes rubocop#7791.

This PR fixes an error on auto-correction for `Layout/BlockEndNewline`
when `}` of multiline block without processing is not on its own line.
bbatsov pushed a commit that referenced this issue Mar 19, 2020
Fixes #7791.

This PR fixes an error on auto-correction for `Layout/BlockEndNewline`
when `}` of multiline block without processing is not on its own line.
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