Skip to content

Commit e971304

Browse files
committed
Add Rails/I18nLocaleTexts match for redirect_back
1 parent 3da25c5 commit e971304

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#880](https://github.com/rubocop/rubocop-rails/pull/880): Add Rails/I18nLocaleTexts match for redirect_back. ([@bensheldon][])

lib/rubocop/cop/rails/i18n_locale_texts.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module Rails
6969
class I18nLocaleTexts < Base
7070
MSG = 'Move locale texts to the locale files in the `config/locales` directory.'
7171

72-
RESTRICT_ON_SEND = %i[validates redirect_to []= mail].freeze
72+
RESTRICT_ON_SEND = %i[validates redirect_to redirect_back []= mail].freeze
7373

7474
def_node_search :validation_message, <<~PATTERN
7575
(pair (sym :message) $str)
@@ -94,7 +94,7 @@ def on_send(node)
9494
add_offense(text_node)
9595
end
9696
return
97-
when :redirect_to
97+
when :redirect_to, :redirect_back
9898
text_node = redirect_to_flash(node).to_a.last
9999
when :[]=
100100
text_node = flash_assignment?(node)

spec/rubocop/cop/rails/i18n_locale_texts_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
RUBY
2727
end
2828

29+
it 'registers an offense when using `redirect_back` with text flash messages' do
30+
expect_offense(<<~RUBY)
31+
redirect_back fallback_location: root_path, notice: "Post created!"
32+
^^^^^^^^^^^^^^^ Move locale texts to the locale files in the `config/locales` directory.
33+
RUBY
34+
end
35+
2936
it 'does not register an offense when using `redirect_to` with localized flash messages' do
3037
expect_no_offenses(<<~RUBY)
3138
redirect_to root_path, notice: t(".success")

0 commit comments

Comments
 (0)