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

Grep/Grep cop occurs an error when running #4

Open
ydah opened this issue Mar 16, 2023 · 3 comments
Open

Grep/Grep cop occurs an error when running #4

ydah opened this issue Mar 16, 2023 · 3 comments

Comments

@ydah
Copy link

ydah commented Mar 16, 2023

Hello.

Grep/Grep cop occurs an error when running.
I have prepared .rubocop.yml as follows from the README:

require:
  - rubocop-grep

Grep/Grep:
  Rules:
    # The simplest rule definition. It warns if the regexp matches your code.
    - Pattern: '\bENV\b'
      Message: Do not refer ENV directly.

The following error occurs:

An error occurred while Grep/Grepx cop was inspecting /Users/ydah/sandbox-rubocop-grep/target.rb.
undefined method `each' for nil:NilClass
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-grep-0.1.0/lib/rubocop/cop/grep/grep.rb:13:in `on_new_investigation'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cop/commissioner.rb:160:in `block (2 levels) in invoke'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cop/commissioner.rb:160:in `block in invoke'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cop/commissioner.rb:160:in `each'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cop/commissioner.rb:160:in `invoke'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cop/commissioner.rb:84:in `investigate'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cop/team.rb:156:in `investigate_partial'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cop/team.rb:98:in `investigate'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:345:in `block in inspect_file'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:344:in `each'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:344:in `flat_map'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:344:in `inspect_file'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:287:in `block in do_inspection_loop'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:314:in `loop'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:164:in `block in file_offenses'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:189:in `file_offense_cache'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:163:in `file_offenses'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:154:in `process_file'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:134:in `each'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:134:in `reduce'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:134:in `each_inspected_file'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:120:in `inspect_files'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/runner.rb:73:in `run'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli.rb:118:in `run_command'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli.rb:125:in `execute_runners'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli.rb:51:in `block in run'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli.rb:77:in `profile_if_needed'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cli.rb:43:in `run'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/exe/rubocop:19:in `block in <top (required)>'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/benchmark.rb:311:in `realtime'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/exe/rubocop:19:in `<top (required)>'
/Users/ydah/.rbenv/versions/3.2.0/bin/rubocop:25:in `load'
/Users/ydah/.rbenv/versions/3.2.0/bin/rubocop:25:in `<top (required)>'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `load'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `kernel_load'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli/exec.rb:23:in `run'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli.rb:491:in `exec'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli.rb:34:in `dispatch'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/cli.rb:28:in `start'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.1/libexec/bundle:45:in `block in <top (required)>'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/Users/ydah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.1/libexec/bundle:33:in `<top (required)>'
/Users/ydah/.rbenv/versions/3.2.0/bin/bundle:25:in `load'
/Users/ydah/.rbenv/versions/3.2.0/bin/bundle:25:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Grep/Grepx cop was inspecting /Users/ydah/sandbox-rubocop-grep/target.rb.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Maybe, It appears that efca293, which hacked for steep, is the cause.
It appears that an error is occurring because the each method is being called for nil because it references cop_config in Grep/Grepx at runtime.

cop_config['Rules'].each do |rule|

This will work with the following fixes, but the cop name in the offense log is still wrong (Grep/Grepx).

- cop_config['Rules'].each do |rule|
+ config['Grep/Grep']['Rules'].each do |rule|

The following offense logs occur:

target.rb:3:1: C: Grep/Grepx: Do not refer ENV directly.
                       ^^^^^

Steps to reproduce the problem

  1. Check out the https://github.com/ydah/sandbox-rubocop-grep
  2. Run bundle install.
  3. Run bundle exec rubocop.

RuboCop version

❯ bundle exec rubocop -V
1.48.1 (using Parser 3.2.1.1, rubocop-ast 1.27.0, running on ruby 3.2.0) [x86_64-darwin21]
  - rubocop-grep 0.1.0
@ydah ydah changed the title Grep/Grep cop get an error when running Grep/Grep cop occurs an error when running Mar 16, 2023
@hoshinotsuyoshi

This comment was marked as outdated.

@hoshinotsuyoshi
Copy link

@pocke I sent a pull request. #6

I would be very happy if you could take a look at it ! :)

@hoshinotsuyoshi
Copy link

I thought updating steep gem would solve this problem.
Submitted another pull request #8 🙏
(As far as I tested, it seems like this will probably be fixed in steep 1.4.0.dev.5 or later.)

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

No branches or pull requests

2 participants