-
-
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.
Add solidus/tax_category_deprecated warning cop
- Loading branch information
Showing
5 changed files
with
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#x](https://github.com/solidusio/rubocop-solidus/pull/x): Add solidus/tax_category_deprecated warning cop. ([@safafa][]) |
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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module Solidus | ||
# This cop finds .tax_category occurrences and suggest using .tax_categories instead. | ||
# | ||
# @example | ||
# | ||
# # bad | ||
# model.tax_category = data | ||
# | ||
# # good | ||
# model.tax_categories = [data] | ||
# | ||
# | ||
# | ||
class TaxCategoryDeprecated < Base | ||
include TargetSolidusVersion | ||
minimum_solidus_version 2.2 | ||
|
||
MSG = 'If you are Using Taxrate model use `.tax_categories = [data]` instead of `.tax_category = data`' | ||
|
||
def_node_matcher :existing_tax_category?, <<~PATTERN | ||
(send ... :tax_category) | ||
PATTERN | ||
|
||
def on_send(node) | ||
return unless existing_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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::Cop::Solidus::TaxCategoryDeprecated, :config do | ||
let(:config) { RuboCop::Config.new } | ||
it 'registers an offense when using `tax_category`' do | ||
expect_offense(<<~RUBY) | ||
model.tax_category | ||
^^^^^^^^^^^^^^^^^^ Solidus/TaxCategoryDeprecated: If you are Using Taxrate model use `.tax_categories = [data]` instead of `.tax_category = data` | ||
RUBY | ||
end | ||
|
||
it 'does not register an offense when using `tax_categories`' do | ||
expect_no_offenses(<<~RUBY) | ||
model.tax_categories | ||
RUBY | ||
end | ||
end |