Skip to content

Commit

Permalink
[Fix rubocop#1244] Fix a false positive for `Rails/ActionControllerFl…
Browse files Browse the repository at this point in the history
…ashBeforeRender` when returning `redirect_to`
  • Loading branch information
Earlopain committed Mar 4, 2024
1 parent 87d94e9 commit fd10b27
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
@@ -0,0 +1 @@
* [#1244](https://github.com/rubocop/rubocop-rails/issues/1244): Fix a false positive for `Rails/ActionControllerFlashBeforeRender` when returning `redirect_to`. ([@earlopain][])
Expand Up @@ -99,6 +99,8 @@ def instance_method_or_block?(node)

def use_redirect_to?(context)
context.right_siblings.compact.any? do |sibling|
# Unwrap `return redirect_to :index`
sibling = sibling.children.first if sibling.return_type? && sibling.children.count == 1
sibling.send_type? && sibling.method?(:redirect_to)
end
end
Expand Down
Expand Up @@ -312,4 +312,20 @@ def create
RUBY
end
end

context 'when using `flash` after `render` and returning `redirect_to` in condition block' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
class HomeController < ApplicationController
def create
if condition
flash[:alert] = "msg"
return redirect_to "https://www.example.com/"
end
render :index
end
end
RUBY
end
end
end

0 comments on commit fd10b27

Please sign in to comment.