-
-
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.
Merge pull request #66 from solidusio/safa/restore-discounted-amount-…
…deprecated-cop Safa/restore discounted amount deprecated cop
- Loading branch information
Showing
7 changed files
with
83 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
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
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module Solidus | ||
# This cop finds .discounted_amount occurrences and suggest using .total_before_tax instead. | ||
# | ||
# @example | ||
# | ||
# # bad | ||
# line_item.discounted_amount | ||
# | ||
# # good | ||
# line_item.total_before_tax | ||
# | ||
# | ||
class DiscountedAmountDeprecated < Base | ||
include TargetSolidusVersion | ||
minimum_solidus_version 2.4 | ||
|
||
MSG = 'Use `.total_before_tax` instead of `.discounted_amount`.' | ||
|
||
def_node_matcher :bad_method?, <<~PATTERN | ||
(send ... :discounted_amount) | ||
PATTERN | ||
|
||
def on_send(node) | ||
return unless bad_method?(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
16 changes: 16 additions & 0 deletions
16
spec/rubocop/cop/solidus/discounted_amount_deprecated_spec.rb
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::Cop::Solidus::DiscountedAmountDeprecated, :config do | ||
it 'registers an offense when using .discounted_amount' do | ||
expect_offense(<<~RUBY) | ||
line_item.discounted_amount | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `.total_before_tax` instead of `.discounted_amount`. | ||
RUBY | ||
end | ||
|
||
it 'does not register an offense when using .total_before_tax' do | ||
expect_no_offenses(<<~RUBY) | ||
line_item.total_before_tax | ||
RUBY | ||
end | ||
end |