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

False positive for ActionControllerFlashBeforeRender when flash is called in a block #1182

Open
HashNotAdam opened this issue Nov 13, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@HashNotAdam
Copy link

When flash is called inside a block, a violation of Rails/ActionControllerFlashBeforeRender is thrown even when the action calls redirect_to.


Expected behavior

A violation should not occur when a redirect is being performed

Actual behavior

Even in a clean action (i.e. no control flow where sometimes it renders and sometimes it redirects), a violation is raised.

Steps to reproduce the problem

This action is reported as violating the rule:

def test
  messages = %w[a b c d]
  messages.each { flash[:error] = _1 }

  redirect_to(some_path)
end

The same problem occurs when called in a multi-line block:

def test
  messages = %w[a b c d]
  messages.each do |message|
    flash[:error] = message
  end

  redirect_to(some_path)
end

The issue does not occur if you assign the array directly to flash:

def test
  messages = %w[a b c d]
  flash[:error] = messages

  redirect_to(some_path)
end

RuboCop version

1.56.4 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.2.2) [arm64-darwin23]
  - rubocop-factory_bot 2.24.0
  - rubocop-i18n 1.14.1
  - rubocop-performance 1.19.1
  - rubocop-rails 2.22.1
  - rubocop-rspec 2.24.1
@koic koic added the bug Something isn't working label Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants