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 Rails/ActiveSupportOnLoad when calling without arguments #1256

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_error_for_rails_active_support_load_hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1256](https://github.com/rubocop/rubocop-rails/pull/1256): Fix an error for `Rails/ActiveSupportOnLoad` when calling without arguments. ([@earlopain][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/active_support_on_load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ActiveSupportOnLoad < Base

def on_send(node)
receiver, method, arguments = *node # rubocop:disable InternalAffairs/NodeDestructuring
return unless receiver && (hook = LOAD_HOOKS[receiver.const_name])
return unless arguments && (hook = LOAD_HOOKS[receiver&.const_name])

preferred = "ActiveSupport.on_load(:#{hook}) { #{method} #{arguments.source} }"
add_offense(node, message: format(MSG, prefer: preferred, current: node.source)) do |corrector|
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/active_support_on_load_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
RUBY
end

it 'does not add offense for include without arguments' do
expect_no_offenses(<<~RUBY)
ActiveRecord::Base.include
RUBY
end

it 'adds offense and corrects when trying to extend a framework class with prepend' do
expect_offense(<<~RUBY)
ActiveRecord::Base.prepend(MyClass)
Expand Down