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 Rails/ActionControllerFlashBeforeRender when flash is called in different method #1360

Closed
ildarkayumov opened this issue Sep 11, 2024 · 3 comments

Comments

@ildarkayumov
Copy link

Expected behavior

When redirect_to is called in controller action and flash is set in different extracted method, the cop should not show any offense.

Actual behavior

Even if methods are very simple implementation, a violation is raised.

Inspecting 1 file
C

Offenses:

app/controllers/users_controller.rb:54:5: C: [Correctable] Rails/ActionControllerFlashBeforeRender: Use flash.now before render.
    flash[:notice] = t(".notice")

Steps to reproduce the problem

  def update
    user.update(user_params)

    prepare_flash_message

    redirect_to users_path
  end

  def prepare_flash_message
    flash[:notice] = t(".notice")
  end

RuboCop version

$ rubocop -V
1.65.1 (using Parser 3.3.5.0, rubocop-ast 1.32.3, running on ruby 3.3.3) [arm64-darwin23]
  - rubocop-capybara 2.21.0
  - rubocop-factory_bot 2.26.1
  - rubocop-performance 1.21.1
  - rubocop-rails 2.26.1
  - rubocop-rspec 3.0.5
  - rubocop-rspec_rails 2.30.0
@mjankowski
Copy link
Contributor

May be fixed by this revert - #1344 - but is not released yet.

@koic
Copy link
Member

koic commented Sep 19, 2024

I plan to release a bug fix version within the next couple of days. Please wait a little longer

@koic koic closed this as completed Sep 19, 2024
@Earlopain
Copy link
Contributor

The PR will not fix this. There is simply no way for rubocop to handle this properly; it is just static analysis. You are probably better of disabling it if this is a common pattern for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants