-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-Add Solidus/TaxCategoryDeprecated cop
This cop was removed earlier as it was giving a lot of false positives. We have re-added this cop again but now with a warning offense so that it doesn't raise any errors for this cop but warns the user to have a look at certain places in the code where something might be wrong.
- Loading branch information
1 parent
e62c4c3
commit dfb5cf2
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
# 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 |