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

Lint/EmptyFile causes error when I run RuboCop with --format=json #8718

Closed
yykamei opened this issue Sep 15, 2020 · 9 comments
Closed

Lint/EmptyFile causes error when I run RuboCop with --format=json #8718

yykamei opened this issue Sep 15, 2020 · 9 comments
Labels

Comments

@yykamei
Copy link

yykamei commented Sep 15, 2020

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.


Expected behavior

RuboCop finishes the analysis without error.

Actual behavior

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>'

Steps to reproduce the problem

You can reproduce this problem with this repository.

  1. Clone this repository and move on to the cloned directory
  2. Run bundle install (Maybe, you should set up your Ruby with rbenv)
  3. Run bundle exec rubocop --cache=false --format=json a.rb

RuboCop version

Master: 03e83a2

$ [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)
@koic koic added the bug label Sep 15, 2020
@rrosenblum
Copy link
Contributor

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}}%

@ybiquitous
Copy link
Contributor

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.

https://github.com/rubocop-hq/rubocop/blob/aa7d8d454de563f081e783c967b8fcceb4c94202/lib/rubocop/cop/base.rb#L106-L111

The cops are: Lint/EmptyFile and Lint/Syntax

https://github.com/rubocop-hq/rubocop/blob/aa7d8d454de563f081e783c967b8fcceb4c94202/lib/rubocop/cop/lint/empty_file.rb#L29

https://github.com/rubocop-hq/rubocop/blob/aa7d8d454de563f081e783c967b8fcceb4c94202/lib/rubocop/cop/lint/syntax.rb#L31

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:

https://github.com/sue445/rubocop-itamae/blob/e724cd0ffab96c1472455bc7ec733ed11b9d3ad2/lib/rubocop/cop/itamae/recipe_path.rb#L30

@fatkodima
Copy link
Contributor

I retested on master - no errors.
Can you verify that was fixed by #8676?

You, probably, would need to clear local rubocop cache, by rm -rf ~/.cache/rubocop_cache before checking.

@marcandre
Copy link
Contributor

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?

Not sure. Being lazy I'd do it on a need only basis.

@ybiquitous
Copy link
Contributor

@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>'

@yykamei
Copy link
Author

yykamei commented Sep 23, 2020

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>'

@ybiquitous
Copy link
Contributor

Hi, I cannot update RuboCop to the latest version due to thi issue, I'd like to really fix it.

The patch in #8718 (comment) by @rrosenblum seems good to me.

Can I open a new PR to apply the patch? Or, is there anything else to consider?

@rrosenblum
Copy link
Contributor

@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.

ybiquitous added a commit to ybiquitous/rubocop that referenced this issue Oct 1, 2020
This change aims to fix the error due to undefined methods of `RuboCop::Cop::Offence::PseudoSourceRange`.

The `RuboCop::Cop::Offence::PseudoSourceRange` class emulates the `Parser::Source::Range` class in the `parser` gem.
(see <https://github.com/whitequark/parser/blob/v2.7.1.5/lib/parser/source/range.rb>)

The `RuboCop::Cop::Offence#location` attribute can have an instance of both these classes.
So, these classes need to have the same interface and semantics for the usage in RuboCop.
@ybiquitous
Copy link
Contributor

@rrosenblum Thanks for your help! I've opened the PR #8823.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants