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/AmbiguousRegexpLiteral: undefined method `receiver' for nil:NilClass #8862

Closed
deepj opened this issue Oct 8, 2020 · 2 comments · Fixed by #8863
Closed

Lint/AmbiguousRegexpLiteral: undefined method `receiver' for nil:NilClass #8862

deepj opened this issue Oct 8, 2020 · 2 comments · Fixed by #8863
Labels

Comments

@deepj
Copy link
Contributor

deepj commented Oct 8, 2020


Expected behavior

This code does not cause the described error below.

class EventTest < ActiveSupport::TestCase
  test '#call' do
    assert_match /confirmed order/, event.description
  end
end

Actual behavior

I got this error:

Inspecting 1 file
Scanning ~/event_test.rb
An error occurred while Lint/AmbiguousRegexpLiteral cop was inspecting ~/event_test.rb.
undefined method `receiver' for nil:NilClass
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb:64:in `method_chain_to_regexp_receiver?'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb:56:in `find_offense_node'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb:50:in `find_offense_node_by'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb:35:in `block in on_new_investigation'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb:32:in `each'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb:32:in `on_new_investigation'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/commissioner.rb:143:in `block (2 levels) in invoke'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/commissioner.rb:152:in `with_cop_error_handling'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/commissioner.rb:142:in `block in invoke'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/commissioner.rb:141:in `each'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/commissioner.rb:141:in `invoke'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/commissioner.rb:83:in `investigate'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/team.rb:152:in `investigate_partial'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cop/team.rb:83:in `investigate'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:315:in `inspect_file'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:259:in `block in do_inspection_loop'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:293:in `block in iterate_until_no_changes'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:286:in `loop'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:132:in `block in file_offenses'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:157:in `file_offense_cache'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:131:in `file_offenses'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:122:in `process_file'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:100:in `each'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:100:in `reduce'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:86:in `inspect_files'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/runner.rb:47:in `run'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cli/command.rb:11:in `run'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cli/environment.rb:18:in `run'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cli.rb:65:in `run_command'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cli.rb:72:in `execute_runners'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/lib/rubocop/cli.rb:41:in `run'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/exe/rubocop:13:in `block in <top (required)>'
~/.rubies/ruby-2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
~/.gem/ruby/2.7.1/gems/rubocop-0.93.0/exe/rubocop:12:in `<top (required)>'
~/.gem/ruby/2.7.1/bin/rubocop:23:in `load'
~/.gem/ruby/2.7.1/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

rubocop -d event_test.rb --only Lint/AmbiguousRegexpLiteral

RuboCop version

$ rubocop -V
0.93.0 (using Parser 2.7.2.0, rubocop-ast 0.7.1, running on ruby 2.7.1 x86_64-darwin18)
@koic koic added the bug label Oct 8, 2020
@marcandre
Copy link
Contributor

marcandre commented Oct 8, 2020

Note: there's already an open PR for this cop: #8708

@koic
Copy link
Member

koic commented Oct 8, 2020

This issue is a recent regression by #8847 💦

koic added a commit to koic/rubocop that referenced this issue Oct 9, 2020
Fixes rubocop#8862.

This PR fixes an error for `Lint/AmbiguousRegexpLiteral`
when using regexp without method calls in nested structure.
@koic koic closed this as completed in #8863 Oct 9, 2020
koic added a commit that referenced this issue Oct 9, 2020
…eral

[Fix #8862] Fix an error for `Lint/AmbiguousRegexpLiteral`
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.

3 participants