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

rubocop:disable Lint errors if the block contains a Lint/UselessAssignment violation #11308

Closed
be-ragheb opened this issue Dec 20, 2022 · 1 comment · Fixed by #11315
Closed
Labels

Comments

@be-ragheb
Copy link

This file causes RuboCop to exit with an error:

# frozen_string_literal: true

# rubocop:disable Lint
unused_variable = 1
puts 'Hello, Lint!'
# rubocop:enable Lint

Expected behavior

I would expect RuboCop to find no issues with the above file and exit cleanly.

Actual behavior

$ rubocop --debug disable_lint.rb         
For /Users/benragheb/Projects/rubocop-bug: Default configuration from /Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /Users/benragheb/Projects/rubocop-bug/disable_lint.rb
An error occurred while Lint/RedundantCopDisableDirective cop was inspecting /Users/benragheb/Projects/rubocop-bug/disable_lint.rb.
undefined method `start_with?' for nil:NilClass
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:308:in `department_marker?'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:287:in `describe'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:229:in `block in add_offense_for_entire_comment'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:229:in `map'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:229:in `add_offense_for_entire_comment'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:220:in `block in add_offenses'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:218:in `each'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:218:in `add_offenses'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:51:in `on_new_investigation'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/commissioner.rb:154:in `block (2 levels) in invoke'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/commissioner.rb:165:in `with_cop_error_handling'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/commissioner.rb:154:in `block in invoke'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/commissioner.rb:154:in `each'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/commissioner.rb:154:in `invoke'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/commissioner.rb:84:in `investigate'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/team.rb:154:in `investigate_partial'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cop/team.rb:82:in `investigate'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:315:in `inspect_file'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:172:in `block in add_redundant_disables'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:193:in `team_for_redundant_disables'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:171:in `add_redundant_disables'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:139:in `block in file_offenses'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:163:in `file_offense_cache'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:137:in `file_offenses'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:128:in `process_file'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:109:in `block in each_inspected_file'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:108:in `each'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:108:in `reduce'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:108:in `each_inspected_file'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:94:in `inspect_files'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/runner.rb:47:in `run'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cli.rb:72:in `run_command'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cli.rb:79:in `execute_runners'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/lib/rubocop/cli.rb:48:in `run'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/exe/rubocop:19:in `block in <top (required)>'
/Users/benragheb/.rvm/rubies/ruby-2.6.10/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/Users/benragheb/.rvm/gems/ruby-2.6.10/gems/rubocop-1.41.0/exe/rubocop:19:in `<top (required)>'
/Users/benragheb/.rvm/gems/ruby-2.6.10/bin/rubocop:23:in `load'
/Users/benragheb/.rvm/gems/ruby-2.6.10/bin/rubocop:23:in `<main>'
/Users/benragheb/.rvm/gems/ruby-2.6.10/bin/ruby_executable_hooks:22:in `eval'
/Users/benragheb/.rvm/gems/ruby-2.6.10/bin/ruby_executable_hooks:22:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Lint/RedundantCopDisableDirective cop was inspecting /Users/benragheb/Projects/rubocop-bug/disable_lint.rb.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.41.0 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on ruby 2.6.10) [x86_64-darwin21]
Finished in 0.1961609999416396 seconds

Steps to reproduce the problem

  1. create empty directory
  2. create Gemfile with gem 'rubocop'
  3. bundle install
  4. create disable_lint.rb with above content
  5. rubocop disable_lint.rb

RuboCop version

1.41.0 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on ruby 2.6.10) [x86_64-darwin21]
@be-ragheb
Copy link
Author

@fatkodima Thank you for addressing this so quickly!

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