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 using return redirect_to #1244

Closed
ccutrer opened this issue Mar 1, 2024 · 0 comments · Fixed by #1246
Closed

Comments

@ccutrer
Copy link
Contributor

ccutrer commented Mar 1, 2024

Expected behavior

When exiting an action early, we often use return redirect_to ..., since the return value doesn't matter, and it saves a line. Unfortunately, this can trigger an offense.

Actual behavior

app/controllers/gradebooks_controller.rb:1038:7: C: Rails/ActionControllerFlashBeforeRender: Use flash.now before render.
      flash[:notice] = t(:speed_grader_disabled, "SpeedGrader is disabled for this course")
      ^^^^^

Steps to reproduce the problem

    unless @context.allows_speed_grader?
      flash[:notice] = t(:speed_grader_disabled, "SpeedGrader is disabled for this course")
      return redirect_to(course_gradebook_path(@context))
    end

RuboCop version

% rubocop -V
1.61.0 (using Parser 3.3.0.5, rubocop-ast 1.31.1, running on ruby 3.1.3) [arm64-darwin21]
  - rubocop-factory_bot 2.25.1
  - rubocop-graphql 1.5.0
  - rubocop-performance 1.20.2
  - rubocop-rails 2.23.1
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.27.0
Earlopain added a commit to Earlopain/rubocop-rails that referenced this issue Mar 4, 2024
…ashBeforeRender` when returning `redirect_to`
Earlopain added a commit to Earlopain/rubocop-rails that referenced this issue Mar 4, 2024
…ashBeforeRender` when returning `redirect_to`
@koic koic closed this as completed in #1246 Mar 4, 2024
koic added a commit that referenced this issue Mar 4, 2024
[Fix #1244] Fix a false positive for `Rails/ActionControllerFlashBeforeRender` when returning `redirect_to`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant