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

Fix an error for Style/RequireOrder when using require inside rescue body #11330

Merged
merged 1 commit into from Dec 25, 2022

Conversation

fatkodima
Copy link
Contributor

For the following code

begin
rescue
  require "foo"
end

I got

undefined method `if_type?' for nil:NilClass

          node.if_type? && !node.modifier_form?
              ^^^^^^^^^
rubocop/lib/rubocop/cop/style/require_order.rb:102:in `not_modifier_form?'
rubocop/lib/rubocop/cop/style/require_order.rb:121:in `sibling_node'
rubocop/lib/rubocop/cop/style/require_order.rb:107:in `block in find_previous_older_sibling'
rubocop/lib/rubocop/cop/style/require_order.rb:106:in `each'
rubocop/lib/rubocop/cop/style/require_order.rb:106:in `find'
rubocop/lib/rubocop/cop/style/require_order.rb:106:in `find_previous_older_sibling'
rubocop/lib/rubocop/cop/style/require_order.rb:87:in `on_send'
rubocop/lib/rubocop/cop/commissioner.rb:137:in `public_send'

Node#left_siblings returns all (sibling) children of the parent node (not only of AST::Node type), but we should work only with nodes.

@bbatsov bbatsov merged commit 36a4120 into rubocop:master Dec 25, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 25, 2022

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants