The combination with Lint/EmptyFile and the --format=json option seems to cause error. Perhaps, this relates the PseudoSourceRange here, but I'm not sure how to fix the problem.
RuboCop finishes the analysis without error.
Error is thrown when processing Lint/EmptyFile.
{"metadata":{"rubocop_version":"0.91.0","ruby_engine":"ruby","ruby_version":"2.7.1","ruby_patchlevel":"83","ruby_platform":"x86_64-linux"},"files":[],"summary":{"offense_count":0,"target_file_count":1,"inspected_file_count":0}}undefined method `last_line' for #<RuboCop::Cop::Offense::PseudoSourceRange:0x00005586068a29b0>
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/cop/offense.rb:175:in `last_line'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/formatter/json_formatter.rb:70:in `hash_for_location'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/formatter/json_formatter.rb:61:in `hash_for_offense'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/formatter/json_formatter.rb:50:in `block in hash_for_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/formatter/json_formatter.rb:50:in `map'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/formatter/json_formatter.rb:50:in `hash_for_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/formatter/json_formatter.rb:28:in `file_finished'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/formatter/formatter_set.rb:49:in `block in file_finished'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/formatter/formatter_set.rb:49:in `each'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/formatter/formatter_set.rb:49:in `file_finished'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/runner.rb:214:in `file_finished'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/runner.rb:123:in `process_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/runner.rb:97:in `block in each_inspected_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/runner.rb:96:in `each'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/runner.rb:96:in `reduce'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/runner.rb:96:in `each_inspected_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/runner.rb:82:in `inspect_files'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/runner.rb:43:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/cli/command.rb:11:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/cli/environment.rb:18:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/cli.rb:65:in `run_command'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/cli.rb:72:in `execute_runners'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/lib/rubocop/cli.rb:41:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/exe/rubocop:13:in `block in <top (required)>'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-03e83a2b234f/exe/rubocop:12:in `<top (required)>'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bin/rubocop:23:in `load'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bin/rubocop:23:in `<top (required)>'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/home/kamei/.rbenv/versions/2.7.1/bin/bundle:23:in `load'
/home/kamei/.rbenv/versions/2.7.1/bin/bundle:23:in `<main>'
You can reproduce this problem with this repository.
bundle install (Maybe, you should set up your Ruby with rbenv)bundle exec rubocop --cache=false --format=json a.rbMaster: 03e83a2b234feaa025333345a0c115751cc4a35e
$ [bundle exec] rubocop -V
0.91.0 (using Parser 2.7.1.4, rubocop-ast 0.4.0, running on ruby 2.7.1 x86_64-linux)
This issue will happen for any cop that registers an offense for a file rather than for a code range.
I have a quick fix for this, however I'd like to discuss the potential impact and how exactly we'd like to fix this. The problem is straight forward, the formatter references last_line and last_column and those values aren't defined for a file based offense.
The easiest solution seems to be to add last_line and last_column to the PseudoSourceRange struct, and then define the values to 0. Do we want to fix the issue this way? Should we ensure that we define all of the public methods from Offense in PseudoSourceRange?
diff --git a/lib/rubocop/cop/offense.rb b/lib/rubocop/cop/offense.rb
index 0da21b0fe..1d0adabee 100644
--- a/lib/rubocop/cop/offense.rb
+++ b/lib/rubocop/cop/offense.rb
@@ -63,10 +63,10 @@ module RuboCop
attr_reader :corrector
PseudoSourceRange = Struct.new(:line, :column, :source_line, :begin_pos,
- :end_pos)
+ :end_pos, :last_line, :last_column)
private_constant :PseudoSourceRange
- NO_LOCATION = PseudoSourceRange.new(1, 0, '', 0, 1).freeze
+ NO_LOCATION = PseudoSourceRange.new(1, 0, '', 0, 1, 0, 0).freeze
# @api private
def initialize(severity, location, message, cop_name, # rubocop:disable Metrics/ParameterLists
rrosenblum@LATLmacK0QUJGH8:~/work/rubocop (master u= origin/master)$ cat test.rb
rrosenblum@LATLmacK0QUJGH8:~/work/rubocop (master u= origin/master)$ b rubocop --format=json test.rb
{"metadata":{"rubocop_version":"0.91.0","ruby_engine":"ruby","ruby_version":"2.6.6","ruby_patchlevel":"146","ruby_platform":"x86_64-darwin18"},"files":[{"path":"test.rb","offenses":[{"severity":"warning","message":"Empty file detected.","cop_name":"Lint/EmptyFile","corrected":false,"correctable":true,"location":{"start_line":1,"start_column":1,"last_line":1,"last_column":1,"length":1,"line":1,"column":1}}]}],"summary":{"offense_count":1,"target_file_count":1,"inspected_file_count":1}}%
I found a workaround to avoid the error: disabling the Lint/EmptyFile cop.
via a configuration file:
AllCops:
NewCops: enable
Lint/EmptyFile:
Enabled: false
via CLI:
rubocop --enable-pending-cops --except=Lint/EmptyFile
This error occurs only on cops using the RuboCop::Cop::Base#add_global_offense method. Because Offense::NO_LOCATION is used only in the #add_global_offense method.
The cops are: Lint/EmptyFile and Lint/Syntax
Lint/Syntax is a basic cop, so I think we could keep it enabled in most cases.
For third-party cops, I found the Itamae/RecipePath cop uses the #add_global_offense method.
So, rubocop-itamae users may need to disable also Itamae/RecipePath:
I retested on master - no errors.
Can you verify that was fixed by https://github.com/rubocop-hq/rubocop/pull/8676?
You, probably, would need to clear local rubocop cache, by rm -rf ~/.cache/rubocop_cache before checking.
The easiest solution seems to be to add
last_lineandlast_columnto thePseudoSourceRangestruct, and then define the values to 0. Do we want to fix the issue this way?
馃憤
Should we ensure that we define all of the public methods from
OffenseinPseudoSourceRange?
Not sure. Being lazy I'd do it on a need only basis.
@fatkodima Thanks for your response, but I could not verify this issue was fixed via c70badc... 馃槙
Here is my reproduction via Docker (to ensure the clean environment):
# Reproduction for https://github.com/rubocop-hq/rubocop/issues/8718
#
# Usage:
# docker build -t rubocop-8718 .
# docker run --rm -it rubocop-8718
FROM ruby:2.7.1-buster
WORKDIR /work
RUN bundle init
RUN bundle add --git https://github.com/rubocop-hq/rubocop rubocop
RUN bundle list
RUN touch a.rb
ENTRYPOINT ["bundle", "exec", "rubocop", "a.rb", "--format=json", "--cache=false", "--enable-pending-cops"]
$ docker build -t rubocop-8718 .
(...omitted...)
$ docker run --rm -it rubocop-8718
{"metadata":{"rubocop_version":"0.91.0","ruby_engine":"ruby","ruby_version":"2.7.1","ruby_patchlevel":"83","ruby_platform":"x86_64-linux"},"files":[],"summary":{"offense_count":0,"target_file_count":1,"inspected_file_count":0}}undefined method `last_line' for #<RuboCop::Cop::Offense::PseudoSourceRange:0x00005607779570c0>
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/cop/offense.rb:175:in `last_line'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:70:in `hash_for_location'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:61:in `hash_for_offense'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:50:in `block in hash_for_file'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:50:in `map'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:50:in `hash_for_file'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:28:in `file_finished'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/formatter_set.rb:49:in `block in file_finished'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/formatter_set.rb:49:in `each'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/formatter_set.rb:49:in `file_finished'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:214:in `file_finished'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:123:in `process_file'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:97:in `block in each_inspected_file'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:96:in `each'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:96:in `reduce'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:96:in `each_inspected_file'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:82:in `inspect_files'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:43:in `run'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli/command.rb:11:in `run'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli/environment.rb:18:in `run'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli.rb:65:in `run_command'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli.rb:72:in `execute_runners'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli.rb:41:in `run'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/exe/rubocop:13:in `block in <top (required)>'
/usr/local/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/usr/local/bundle/bundler/gems/rubocop-c70badc16842/exe/rubocop:12:in `<top (required)>'
/usr/local/bundle/bin/rubocop:23:in `load'
/usr/local/bundle/bin/rubocop:23:in `<top (required)>'
/usr/local/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `load'
/usr/local/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/lib/ruby/2.7.0/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/2.7.0/bundler/cli.rb:476:in `exec'
/usr/local/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/local/lib/ruby/2.7.0/bundler/cli.rb:30:in `dispatch'
/usr/local/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/local/lib/ruby/2.7.0/bundler/cli.rb:24:in `start'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:46:in `block in <top (required)>'
/usr/local/lib/ruby/2.7.0/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:34:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Same here. I updated this repo but can still reproduce the problem without cache:
$ rm -rf ~/.cache/rubocop_cache && bundle exec rubocop --cache=false --format=json a.rb
{"metadata":{"rubocop_version":"0.91.0","ruby_engine":"ruby","ruby_version":"2.7.1","ruby_patchlevel":"83","ruby_platform":"x86_64-linux"},"files":[],"summary":{"offense_count":0,"target_file_count":1,"inspected_file_count":0}}undefined method `last_line' for #<RuboCop::Cop::Offense::PseudoSourceRange:0x0000562bbe567a30>
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/cop/offense.rb:175:in `last_line'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:70:in `hash_for_location'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:61:in `hash_for_offense'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:50:in `block in hash_for_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:50:in `map'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:50:in `hash_for_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/json_formatter.rb:28:in `file_finished'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/formatter_set.rb:49:in `block in file_finished'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/formatter_set.rb:49:in `each'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/formatter/formatter_set.rb:49:in `file_finished'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:214:in `file_finished'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:123:in `process_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:97:in `block in each_inspected_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:96:in `each'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:96:in `reduce'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:96:in `each_inspected_file'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:82:in `inspect_files'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/runner.rb:43:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli/command.rb:11:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli/environment.rb:18:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli.rb:65:in `run_command'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli.rb:72:in `execute_runners'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/lib/rubocop/cli.rb:41:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/exe/rubocop:13:in `block in <top (required)>'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rubocop-c70badc16842/exe/rubocop:12:in `<top (required)>'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bin/rubocop:23:in `load'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bin/rubocop:23:in `<top (required)>'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/home/kamei/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/home/kamei/.rbenv/versions/2.7.1/bin/bundle:23:in `load'
/home/kamei/.rbenv/versions/2.7.1/bin/bundle:23:in `<main>'
Hi, I cannot update RuboCop to the latest version due to thi issue, I'd like to really fix it.
The patch in https://github.com/rubocop-hq/rubocop/issues/8718#issuecomment-692723452 by @rrosenblum seems good to me.
Can I open a new PR to apply the patch? Or, is there anything else to consider?
@ybiquitous Yes, the patch that I mentioned can be applied and opened as a PR to fix this. Maybe there is some sort of test case that we'll want to introduce to show the fixed behavior. Feel free to create the PR, otherwise I can take care of it.
@rrosenblum Thanks for your help! I've opened the PR #8823.
Most helpful comment
This issue will happen for any cop that registers an offense for a file rather than for a code range.
I have a quick fix for this, however I'd like to discuss the potential impact and how exactly we'd like to fix this. The problem is straight forward, the formatter references
last_lineandlast_columnand those values aren't defined for a file based offense.The easiest solution seems to be to add
last_lineandlast_columnto thePseudoSourceRangestruct, and then define the values to 0. Do we want to fix the issue this way? Should we ensure that we define all of the public methods fromOffenseinPseudoSourceRange?