Rubocop: undefined method `location' for nil:NilClass @ cop.rb:176

Created on 18 Nov 2019  路  1Comment  路  Source: rubocop-hq/rubocop

Be clear, concise and precise in your description of the problem.
Open an issue with a descriptive title and a summary in grammatically correct,
complete sentences.

Use the template below when reporting bugs. Please, make sure that
you're running the latest stable RuboCop and that the problem you're reporting
hasn't been reported (and potentially fixed) already.

Before filing the ticket you should replace all text above the horizontal
rule with your own words.


Expected behavior

Describe here how you expected RuboCop to behave in this particular situation

To do the "rubocop --auto-correct --disable-uncorrectable" command and finish the analysis and correction properly

Actual behavior

Describe here what actually happened.

An error is prompted

106 files inspected, 9554 offenses detected, 9526 offenses corrected undefined methodlocation' for nil:NilClass
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cop/cop.rb:176:in disable_uncorrectable' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cop/cop.rb:161:incorrect'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cop/cop.rb:134:in add_offense' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cop/lint/syntax.rb:35:inadd_offense_from_diagnostic'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cop/lint/syntax.rb:24:in block in offenses_from_processed_source' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cop/lint/syntax.rb:23:ineach'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cop/lint/syntax.rb:23:in offenses_from_processed_source' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cop/team.rb:39:ininspect_file'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:290:in inspect_file' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:238:inblock in do_inspection_loop'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:270:in block in iterate_until_no_changes' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:263:inloop'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:263:in iterate_until_no_changes' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:234:indo_inspection_loop'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:119:in block in file_offenses' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:137:infile_offense_cache'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:117:in file_offenses' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:108:inprocess_file'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:87:in block in each_inspected_file' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:86:ineach'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:86:in reduce' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:86:ineach_inspected_file'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:73:in inspect_files' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/runner.rb:39:inrun'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cli.rb:213:in execute_runner' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cli.rb:80:inexecute_runners'
/home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/lib/rubocop/cli.rb:51:in run' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/exe/rubocop:13:inblock in /home/djigo/.rvm/rubies/ruby-2.5.5/lib/ruby/2.5.0/benchmark.rb:308:in realtime' /home/djigo/.rvm/gems/ruby-2.5.5/gems/rubocop-0.76.0/exe/rubocop:12:in /home/djigo/.rvm/gems/ruby-2.5.5/bin/rubocop:23:in load' /home/djigo/.rvm/gems/ruby-2.5.5/bin/rubocop:23:in

'
/home/djigo/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:24:in eval' /home/djigo/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:24:in
'`

Steps to reproduce the problem

This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.

Run "rubocop --auto-correct --disable-uncorrectable"

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
0.76.0 (using Parser 2.6.5.0, running on ruby 2.5.5 x86_64-linux)

$ [bundle exec] rubocop -V
0.76.0 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-linux)
bug

Most helpful comment

Use a file with a syntax error to reproduce this:

$ echo \" > 7513.rb
$ rubocop --auto-correct --disable-uncorrectable 7513.rb
Inspecting 1 file
.

0 files inspected, no offenses detected
undefined method `location' for nil:NilClass
/Users/buehmann/dev/rubocop/lib/rubocop/cop/cop.rb:176:in `disable_uncorrectable'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/cop.rb:161:in `correct'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/cop.rb:134:in `add_offense'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/lint/syntax.rb:35:in `add_offense_from_diagnostic'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/lint/syntax.rb:24:in `block in offenses_from_processed_source'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/lint/syntax.rb:23:in `each'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/lint/syntax.rb:23:in `offenses_from_processed_source'

>All comments

Use a file with a syntax error to reproduce this:

$ echo \" > 7513.rb
$ rubocop --auto-correct --disable-uncorrectable 7513.rb
Inspecting 1 file
.

0 files inspected, no offenses detected
undefined method `location' for nil:NilClass
/Users/buehmann/dev/rubocop/lib/rubocop/cop/cop.rb:176:in `disable_uncorrectable'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/cop.rb:161:in `correct'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/cop.rb:134:in `add_offense'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/lint/syntax.rb:35:in `add_offense_from_diagnostic'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/lint/syntax.rb:24:in `block in offenses_from_processed_source'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/lint/syntax.rb:23:in `each'
/Users/buehmann/dev/rubocop/lib/rubocop/cop/lint/syntax.rb:23:in `offenses_from_processed_source'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndreiMotinga picture AndreiMotinga  路  3Comments

deivid-rodriguez picture deivid-rodriguez  路  3Comments

mlammers picture mlammers  路  3Comments

david942j picture david942j  路  3Comments

herwinw picture herwinw  路  3Comments