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

Style/DisableCopsWithinSourceCodeDirectory errors out #9431

Closed
coding-bunny opened this issue Jan 28, 2021 · 0 comments · Fixed by #9432
Closed

Style/DisableCopsWithinSourceCodeDirectory errors out #9431

coding-bunny opened this issue Jan 28, 2021 · 0 comments · Fixed by #9432
Labels

Comments

@coding-bunny
Copy link

Expected behavior

I expect the Cop to not throw an error

Actual behavior

Right now the specified Cop throws an error when running the RuboCop linter.

An error occurred while Style/DisableCopsWithinSourceCodeDirective cop was inspecting /home/coding-bunny/RubymineProjects/inkycop/spec/spec_helper.rb.
undefined method `[]' for nil:NilClass
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb:74:in `directive_cops'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb:42:in `block in on_new_investigation'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb:41:in `each'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb:41:in `on_new_investigation'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/commissioner.rb:157:in `block (2 levels) in invoke'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/commissioner.rb:166:in `with_cop_error_handling'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/commissioner.rb:156:in `block in invoke'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/commissioner.rb:155:in `each'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/commissioner.rb:155:in `invoke'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/commissioner.rb:84:in `investigate'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/team.rb:157:in `investigate_partial'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cop/team.rb:83:in `investigate'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:315:in `inspect_file'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:259:in `block in do_inspection_loop'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:293:in `block in iterate_until_no_changes'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:286:in `loop'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:132:in `block in file_offenses'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:157:in `file_offense_cache'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:131:in `file_offenses'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:122:in `process_file'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:100:in `each'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:100:in `reduce'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:86:in `inspect_files'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/runner.rb:47:in `run'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cli/command.rb:11:in `run'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cli/environment.rb:18:in `run'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cli.rb:65:in `run_command'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cli.rb:72:in `execute_runners'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/lib/rubocop/cli.rb:41:in `run'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/exe/rubocop:13:in `block in <top (required)>'
/home/coding-bunny/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/gems/rubocop-1.9.0/exe/rubocop:12:in `<top (required)>'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/bin/rubocop:23:in `load'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/bin/rubocop:23:in `<main>'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:24:in `eval'
/home/coding-bunny/.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:24:in `<main>'

Steps to reproduce the problem

This happens in 8 different files.
This is my spec_helper.rb for example:

# frozen_string_literal: true

require('simplecov')
require('rspec')
::SimpleCov.start

# Extend the $LOAD_PATH with our lib library. This allows us to require the gem normally like Bundler would do.
$LOAD_PATH.unshift(::File.expand_path('../lib', __dir__))

require('inky_cop')

::RSpec.configure do |config|
  # Enable flags like --only-failures and --next-failure
  config.example_status_persistence_file_path = '.rspec_status'

  # Disable RSpec exposing methods globally on `Module` and `main`
  config.disable_monkey_patching!

  config.expect_with(:rspec) do |c|
    c.syntax = :expect
  end
end

RuboCop version

➜  inkycop git:(coding-bunny/rubocop_upgrade) ✗ bundle exec rubocop -V
1.9.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.7.2 x86_64-linux)
  - rubocop-performance 1.9.2
  - rubocop-rake 0.5.1
@koic koic added the bug label Jan 28, 2021
koic added a commit to koic/rubocop that referenced this issue Jan 28, 2021
…eDirective`

Fixes rubocop#9431.

Fix the following error for `Style/DisableCopsWithinSourceCodeDirective`
when using leading source comment.

```console
% cat example.rb
# frozen_string_literal: true

class Foo
end

% bundle exec rubocop example.rb --only Style/DisableCopsWithinSourceCodeDirective -d
(snip)

Inspecting 1 file
Scanning /Users/koic/src/github.com/koic/rubocop-issues/master/example.rb
An error occurred while Style/DisableCopsWithinSourceCodeDirective cop
was inspecting
/Users/koic/src/github.com/koic/rubocop-issues/master/example.rb.
undefined method `[]' for nil:NilClass
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/style/
disable_cops_within_source_code_directive.rb:74:in `directive_cops'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/style/
disable_cops_within_source_code_directive.rb:42:in `block in on_new_investigation'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/style/
disable_cops_within_source_code_directive.rb:41:in `each'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/style/
disable_cops_within_source_code_directive.rb:41:in `on_new_investigation'
```
bbatsov pushed a commit that referenced this issue Jan 28, 2021
…ive`

Fixes #9431.

Fix the following error for `Style/DisableCopsWithinSourceCodeDirective`
when using leading source comment.

```console
% cat example.rb
# frozen_string_literal: true

class Foo
end

% bundle exec rubocop example.rb --only Style/DisableCopsWithinSourceCodeDirective -d
(snip)

Inspecting 1 file
Scanning /Users/koic/src/github.com/koic/rubocop-issues/master/example.rb
An error occurred while Style/DisableCopsWithinSourceCodeDirective cop
was inspecting
/Users/koic/src/github.com/koic/rubocop-issues/master/example.rb.
undefined method `[]' for nil:NilClass
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/style/
disable_cops_within_source_code_directive.rb:74:in `directive_cops'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/style/
disable_cops_within_source_code_directive.rb:42:in `block in on_new_investigation'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/style/
disable_cops_within_source_code_directive.rb:41:in `each'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/style/
disable_cops_within_source_code_directive.rb:41:in `on_new_investigation'
```
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