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 instance variables misdetection in ActionDispatch callbacks #48

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.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## master (unreleased)

* [#48](https://github.com/rubocop/rubocop-thread_safety/pull/48): Do not report instance variables in `ActionDispatch` callbacks in singleton methods. ([@viralpraxis][])
* [#43](https://github.com/rubocop/rubocop-thread_safety/pull/43): Make detection of ActiveSupport's `class_attribute` configurable. ([@viralpraxis][])
* [#42](https://github.com/rubocop/rubocop-thread_safety/pull/42): Fix some `InstanceVariableInClassMethod` cop false positive offenses. ([@viralpraxis][])
* [#41](https://github.com/rubocop/rubocop-thread_safety/pull/41): Drop support for MRI older than 2.7. ([@viralpraxis][])
Expand Down
16 changes: 16 additions & 0 deletions lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,22 @@ def match_name?(arg_name, method_name)
(block (send (const nil? :Struct) :new ...) _ ({def defs} ...))
(block (send (const nil? :Class) :new ...) _ ({def defs} ...))
(block (send (const nil? :Data) :define ...) _ ({def defs} ...))
(block
(send nil?
{
:prepend_around_action
:prepend_before_action
:before_action
:append_before_action
:around_action
:append_around_action
:append_after_action
:after_action
:prepend_after_action
}
)
...
)
}
PATTERN
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,28 @@ def another_method(params)
end
RUBY
end

context 'with `ActionDispatch` callbacks' do
%i[
prepend_around_action
prepend_before_action
before_action
append_before_action
around_action
append_around_action
append_after_action
after_action
prepend_after_action
].each do |action_dispatch_callback_name|
it "registers no offense for `#{action_dispatch_callback_name}` callback" do
expect_no_offenses(<<~RUBY)
def self.foo
#{action_dispatch_callback_name} do
@language = :haskell
end
end
RUBY
end
end
end
end