Skip to content

Commit

Permalink
Merge pull request #48 from viralpraxis/fix-ivars-misdetection-in-act…
Browse files Browse the repository at this point in the history
…ion-dispatch-callbacks

Fix instance variables misdetection in `ActionDispatch` callbacks
  • Loading branch information
viralpraxis authored Sep 15, 2024
2 parents fddd9c2 + 6002dfc commit 489ebd2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
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

0 comments on commit 489ebd2

Please sign in to comment.