Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1539](https://github.com/rubocop/rubocop-rails/issues/1539): Fix an error in `Rails/ActionControllerFlashBeforeRender` when `flash` is used inside a block followed by method chaining. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def instance_method_or_block?(node)
end

def use_redirect_to?(context)
context.right_siblings.compact.any? do |sibling|
context.right_siblings.any? do |sibling|
next unless sibling.is_a?(AST::Node)

# Unwrap `return redirect_to :index`
sibling = sibling.children.first if sibling.return_type? && sibling.children.one?
sibling.send_type? && sibling.method?(:redirect_to)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,16 @@ def create
RUBY
end
end

context 'when `flash` is used inside a block followed by method chaining' do
it 'does not register an offense and corrects' do
expect_no_offenses(<<~RUBY)
class NonController < ApplicationRecord
before_action do
flash[:notice] = 'hello'
end.do_something
end
RUBY
end
end
end