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
An error occurred while Style/SafeNavigation cop was inspecting file: undefined method 'parent' for nil:NilClass #7171
Labels
Comments
koic
added a commit
to koic/rubocop
that referenced
this issue
Jun 25, 2019
Fixes rubocop#7171. This PR fixes an error for `Style/SafeNavigation` when using `unless nil?` as a safeguarded. ```ruby # example.rb class Object # @yield [Object] def tap_and_return yield self unless nil? end end ``` ```console % rubocop --only Style/SafeNavigation -d For /private/tmp/7171: configuration from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/config/default.yml Inspecting 1 file Scanning /private/tmp/7171/example.rb An error occurred while Style/SafeNavigation cop was inspecting /private/tmp/7171/example.rb:4:4. undefined method `parent' for nil:NilClass /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/safe_navigation.rb:227:in `method_called?' /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/safe_navigation.rb:111:in `use_var_only_in_unless_modifier?' ```
8 tasks
I reproduced it and opened a PR #7172. Thanks! |
bbatsov
pushed a commit
that referenced
this issue
Jun 25, 2019
Fixes #7171. This PR fixes an error for `Style/SafeNavigation` when using `unless nil?` as a safeguarded. ```ruby # example.rb class Object # @yield [Object] def tap_and_return yield self unless nil? end end ``` ```console % rubocop --only Style/SafeNavigation -d For /private/tmp/7171: configuration from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/config/default.yml Inspecting 1 file Scanning /private/tmp/7171/example.rb An error occurred while Style/SafeNavigation cop was inspecting /private/tmp/7171/example.rb:4:4. undefined method `parent' for nil:NilClass /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/safe_navigation.rb:227:in `method_called?' /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/safe_navigation.rb:111:in `use_var_only_in_unless_modifier?' ```
bbatsov
pushed a commit
that referenced
this issue
Jun 25, 2019
Fixes #7171. This PR fixes an error for `Style/SafeNavigation` when using `unless nil?` as a safeguarded. ```ruby # example.rb class Object # @yield [Object] def tap_and_return yield self unless nil? end end ``` ```console % rubocop --only Style/SafeNavigation -d For /private/tmp/7171: configuration from /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/config/default.yml Inspecting 1 file Scanning /private/tmp/7171/example.rb An error occurred while Style/SafeNavigation cop was inspecting /private/tmp/7171/example.rb:4:4. undefined method `parent' for nil:NilClass /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/safe_navigation.rb:227:in `method_called?' /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/safe_navigation.rb:111:in `use_var_only_in_unless_modifier?' ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
Rubocop processes files without any errors encountered.
Actual behavior
Rubocop raises a Style/SafeNavigation error when inspecting file:
Steps to reproduce the problem
RuboCop version
Also happening on 0.70.0
The text was updated successfully, but these errors were encountered: