Skip to content

Conversation

5hun-s
Copy link

@5hun-s 5hun-s commented Aug 31, 2025

Fix #1182

This PR fixes a false positive for Rails/ActionControllerFlashBeforeRender when flash is called in a block.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.
@5hun-s 5hun-s marked this pull request as ready for review August 31, 2025 01:07
@5hun-s 5hun-s changed the title [Fix rubocop#1182] Fix a false positive for Rails/ActionControllerFlashBeforeRender [Fix #1182] Fix a false positive for Rails/ActionControllerFlashBeforeRender Sep 1, 2025
Comment on lines 404 to 405
messages = %w[fizz buzz fizzbuzz]
messages.each { flash[:alert] = _1 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metasyntactic variables are generally preferred to be foo, bar, and baz. Also, unless there is a specific reason, please use a regular block instead of numbered block parameter sytax.

Suggested change
messages = %w[fizz buzz fizzbuzz]
messages.each { flash[:alert] = _1 }
messages = %w[foo bar baz]
messages.each { |message| flash[:alert] = message }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, thank you.

expect_no_offenses(<<~RUBY)
class HomeController < ApplicationController
def create
messages = %w[fizz buzz fizzbuzz]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
messages = %w[fizz buzz fizzbuzz]
messages = %w[foo bar baz]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@5hun-s 5hun-s force-pushed the fix_false_positive_for_rails_action_controller_flash_before_render branch from 73630a2 to 64fee7d Compare September 15, 2025 01:58
@koic
Copy link
Member

koic commented Sep 15, 2025

@5hun-s Can you rebase with the latest master branch to resolve the CI failures?

@5hun-s 5hun-s force-pushed the fix_false_positive_for_rails_action_controller_flash_before_render branch from 64fee7d to 87e5bbf Compare September 16, 2025 03:39
@5hun-s
Copy link
Author

5hun-s commented Sep 16, 2025

@koic I've done it.

@koic koic merged commit 60dd19b into rubocop:master Sep 16, 2025
15 checks passed
@koic
Copy link
Member

koic commented Sep 16, 2025

Thanks!

@5hun-s 5hun-s deleted the fix_false_positive_for_rails_action_controller_flash_before_render branch September 16, 2025 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants