Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-Add Solidus/TaxCategoryDeprecated cop #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ Solidus/SpreeTDeprecated:
Enabled: true
VersionAdded: '0.1.0'
Reference: 'https://github.com/solidusio/rubocop-solidus/issues/22'

Solidus/TaxCategoryDeprecated:
Description: 'Checks if .tax_category=Instance is being used and suggest to replace it with .tax_categories=<Array of Instances>'
Enabled: true
VersionAdded: '0.1.4'
Reference: 'https://github.com/solidusio/solidus/issues/1836'
32 changes: 32 additions & 0 deletions lib/rubocop/cop/solidus/tax_category_deprecated.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module RuboCop
module Cop
module Solidus
# This cop finds tax_category= usages and suggests the usage of tax_categories= instead.
# This cop is needed as tax_category= has been deprecated in future version.
#
# @example EnforcedStyle:
# # bad
# model.tax_category = data
#
# # good
# model.tax_categories = [data]
#
class TaxCategoryDeprecated < Base
MSG = 'tax_category= is deprecated and will be removed from Solidus 3.0. Please use tax_categories= instead. If this call is not from a Spree::TaxRate object then it is false positive.'

# @!method bad_method?(node)
def_node_matcher :tax_category?, <<~PATTERN
(send (...) :tax_category= (...))
PATTERN

def on_send(node)
return unless tax_category?(node)

add_offense(node, severity: :warning)
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/rubocop/cop/solidus_cops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
require_relative 'solidus/spree_icon_deprecated'
require_relative 'solidus/spree_refund_call_perform'
require_relative 'solidus/spree_t_deprecated'
require_relative 'solidus/tax_category_deprecated'
32 changes: 32 additions & 0 deletions spec/rubocop/cop/solidus/tax_category_deprecated_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Solidus::TaxCategoryDeprecated, :config do
let(:config) { RuboCop::Config.new('Solidus/TaxCategoryDeprecated' => { 'Enabled' => true }) }

it 'registers a warning when using `#.tax_category = `' do
expect_offense(<<~RUBY, severity: :warning)
model.tax_category = data
^^^^^^^^^^^^^^^^^^^^^^^^^ tax_category= is deprecated and will be removed from Solidus 3.0. Please use tax_categories= instead. If this call is not from a Spree::TaxRate object then it is false positive.
RUBY
end

it 'registers a warning when using `#.tax_category =`' do
expect_offense(<<~RUBY, severity: :warning)
model.tax_category =data
^^^^^^^^^^^^^^^^^^^^^^^^ tax_category= is deprecated and will be removed from Solidus 3.0. Please use tax_categories= instead. If this call is not from a Spree::TaxRate object then it is false positive.
RUBY
end

it 'registers a warning when using `#.tax_category= `' do
expect_offense(<<~RUBY, severity: :warning)
model.tax_category= data
^^^^^^^^^^^^^^^^^^^^^^^^ tax_category= is deprecated and will be removed from Solidus 3.0. Please use tax_categories= instead. If this call is not from a Spree::TaxRate object then it is false positive.
RUBY
end

it 'does not register any offense when using `#.tax_categories=`' do
expect_no_offenses(<<~RUBY)
model.tax_categories = [data]
RUBY
end
end
Loading