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

Error undefined method `source' for nil:NilClass #3039

Closed
PizzaPill opened this issue Apr 13, 2016 · 1 comment
Closed

Error undefined method `source' for nil:NilClass #3039

PizzaPill opened this issue Apr 13, 2016 · 1 comment

Comments

@PizzaPill
Copy link

I'm getting a undefined method 'source' for nil:NilClass error when I use rubocop with the --auto-correct argument. The cops Performance/StartWith and Performance/EndWith seem to be affected. If I run rubocop without them it works, i.e.rubocop -D --except Performance/StartWith,Performance/EndWith --auto-correct. It happens at least with rubocop v. 0.39.0.

The offending line for Performance/EndWith looks like this:
expect(subject.spin).to match(/\n\n\n\n\z/)

The offending line for Performance/StartWith looks like this:
expect(unspun).to match(/\AParagraph/)

output:

[snip]
165 files inspected, 178 offenses detected
undefined method `source' for nil:NilClass
[redacted]/gems/rubocop-0.39.0/lib/rubocop/cop/performance/start_with.rb:49:in `block (2 levels) in autocorrect'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/cop/corrector.rb:57:in `block (2 levels) in rewrite'
[redacted]/gems/parser-2.3.0.7/lib/parser/source/rewriter.rb:194:in `transaction'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/cop/corrector.rb:56:in `block in rewrite'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/cop/corrector.rb:54:in `each'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/cop/corrector.rb:54:in `rewrite'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/cop/team.rb:132:in `autocorrect_all_cops'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/cop/team.rb:105:in `autocorrect'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/cop/team.rb:60:in `inspect_file'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/runner.rb:203:in `inspect_file'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/runner.rb:173:in `block in do_inspection_loop'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/runner.rb:163:in `loop'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/runner.rb:163:in `do_inspection_loop'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/runner.rb:87:in `process_file'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/runner.rb:59:in `block in inspect_files'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/runner.rb:57:in `each'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/runner.rb:57:in `inspect_files'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/runner.rb:35:in `run'
[redacted]/gems/rubocop-0.39.0/lib/rubocop/cli.rb:30:in `run'
[redacted]/gems/rubocop-0.39.0/bin/rubocop:14:in `block in <top (required)>'
[redacted]/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
[redacted]/gems/rubocop-0.39.0/bin/rubocop:13:in `<top (required)>'
[redacted]/bin/rubocop:23:in `load'
[redacted]/bin/rubocop:23:in `<main>'
[redacted]/bin/ruby_executable_hooks:15:in `eval'
[redacted]/bin/ruby_executable_hooks:15:in `<main>'
bbatsov added a commit that referenced this issue Apr 22, 2016
[Fix #3039] Accept match without receiver in StartWith and EndWith
@PizzaPill
Copy link
Author

Thanks for your good work!

2016-04-22 20:00 GMT+02:00 Bozhidar Batsov [email protected]:

Closed #3039 #3039 via d677e12
d677e12
.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#3039 (comment)

Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
`Performance/StartWith` accepts `match` without a receiver, e.g.

    expect(test).to match(/\A\n/)
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

1 participant