Skip to content

Commit

Permalink
Merge pull request #1009 from fatkodima/i18n_locale_texts-flash_now
Browse files Browse the repository at this point in the history
Support `flash.now` for `Rails/I18nLocaleTexts`
  • Loading branch information
koic authored May 26, 2023
2 parents d45d052 + b2bb010 commit b70b1d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/change_support_flash_now_for.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1007](https://github.com/rubocop/rubocop-rails/issues/1007): Support `flash.now` for `Rails/I18nLocaleTexts`. ([@fatkodima][])
6 changes: 5 additions & 1 deletion lib/rubocop/cop/rails/i18n_locale_texts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ class I18nLocaleTexts < Base
PATTERN

def_node_matcher :flash_assignment?, <<~PATTERN
(send (send nil? :flash) :[]= _ $str)
(send
{
(send nil? :flash)
(send (send nil? :flash) :now)
} :[]= _ $str)
PATTERN

def_node_search :mail_subject, <<~PATTERN
Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/cop/rails/i18n_locale_texts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@
RUBY
end

it 'registers an offense when assigning to `flash.now` text messages' do
expect_offense(<<~RUBY)
flash.now[:notice] = "Post created!"
^^^^^^^^^^^^^^^ Move locale texts to the locale files in the `config/locales` directory.
RUBY
end

it 'does not register an offense when assigning to `flash.now` localized messages' do
expect_no_offenses(<<~RUBY)
flash.now[:notice] = t(".success")
RUBY
end

it 'registers an offense when using `mail` with text subject' do
expect_offense(<<~RUBY)
mail(to: user.email, subject: "Welcome to My Awesome Site")
Expand Down

0 comments on commit b70b1d8

Please sign in to comment.