Skip to content

Commit

Permalink
Include ignoredNode module to avoid clobbering for SpreeTDeprecated cop
Browse files Browse the repository at this point in the history
  • Loading branch information
safafa committed Oct 17, 2023
1 parent c1220d4 commit 45656f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rubocop/cop/solidus/spree_t_deprecated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module Solidus
#
class SpreeTDeprecated < Base
extend AutoCorrector
include IgnoredNode
MSG = 'Use I18n.t instead of Spree.t which has been deprecated in future versions.'

RESTRICT_ON_SEND = %i[t].freeze
Expand All @@ -58,8 +59,11 @@ def on_send(node)
return unless spree_t?(node).include?(:Spree)

add_offense(node) do |corrector|
next if part_of_ignored_node?(node)

corrector.replace(node, corrected_statement(node))
end
ignore_node(node)
end

# rubocop:disable Metrics/MethodLength
Expand Down
28 changes: 28 additions & 0 deletions spec/rubocop/cop/solidus/spree_t_deprecated_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@
I18n.t(:solidus_store, scope: [:custom_scope], email: params[:email])
RUBY
end

context 'when nested correction' do
it 'registers an offense when using `#bad_method`' do
expect_offense(<<~RUBY)
Spree.t(:solidus_store, resource: Spree.t(:test))
^^^^^^^^^^^^^^ Use I18n.t instead of Spree.t which has been deprecated in future versions.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use I18n.t instead of Spree.t which has been deprecated in future versions.
RUBY

expect_correction(<<~RUBY)
I18n.t(:solidus_store, scope: :spree, resource: I18n.t(:test, scope: :spree))
RUBY
end
end
end

describe 'first argument is a string' do
Expand Down Expand Up @@ -183,5 +197,19 @@
I18n.t('solidus_store', scope: [:custom_scope], email: params[:email])
RUBY
end

context 'when nested correction' do
it 'registers an offense when using `#bad_method`' do
expect_offense(<<~RUBY)
Spree.t(:solidus_store, resource: Spree.t(:test))
^^^^^^^^^^^^^^ Use I18n.t instead of Spree.t which has been deprecated in future versions.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use I18n.t instead of Spree.t which has been deprecated in future versions.
RUBY

expect_correction(<<~RUBY)
I18n.t(:solidus_store, scope: :spree, resource: I18n.t(:test, scope: :spree))
RUBY
end
end
end
end

0 comments on commit 45656f8

Please sign in to comment.