Skip to content

Commit b70b1d8

Browse files
authored
Merge pull request #1009 from fatkodima/i18n_locale_texts-flash_now
Support `flash.now` for `Rails/I18nLocaleTexts`
2 parents d45d052 + b2bb010 commit b70b1d8

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1007](https://github.com/rubocop/rubocop-rails/issues/1007): Support `flash.now` for `Rails/I18nLocaleTexts`. ([@fatkodima][])

lib/rubocop/cop/rails/i18n_locale_texts.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ class I18nLocaleTexts < Base
8080
PATTERN
8181

8282
def_node_matcher :flash_assignment?, <<~PATTERN
83-
(send (send nil? :flash) :[]= _ $str)
83+
(send
84+
{
85+
(send nil? :flash)
86+
(send (send nil? :flash) :now)
87+
} :[]= _ $str)
8488
PATTERN
8589

8690
def_node_search :mail_subject, <<~PATTERN

spec/rubocop/cop/rails/i18n_locale_texts_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@
5252
RUBY
5353
end
5454

55+
it 'registers an offense when assigning to `flash.now` text messages' do
56+
expect_offense(<<~RUBY)
57+
flash.now[:notice] = "Post created!"
58+
^^^^^^^^^^^^^^^ Move locale texts to the locale files in the `config/locales` directory.
59+
RUBY
60+
end
61+
62+
it 'does not register an offense when assigning to `flash.now` localized messages' do
63+
expect_no_offenses(<<~RUBY)
64+
flash.now[:notice] = t(".success")
65+
RUBY
66+
end
67+
5568
it 'registers an offense when using `mail` with text subject' do
5669
expect_offense(<<~RUBY)
5770
mail(to: user.email, subject: "Welcome to My Awesome Site")

0 commit comments

Comments
 (0)