rubocop-solidus 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -6
- data/.rubocop_todo.yml +15 -0
- data/CHANGELOG.md +17 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +16 -10
- data/README.md +49 -11
- data/Rakefile +6 -1
- data/config/default.yml +10 -10
- data/docs/cops.md +19 -0
- data/docs/cops_solidus.md +276 -0
- data/lib/rubocop/cop/mixin/target_solidus_version.rb +4 -0
- data/lib/rubocop/cop/solidus/class_eval_decorator.rb +12 -16
- data/lib/rubocop/cop/solidus/reimbursement_hook_deprecated.rb +17 -0
- data/lib/rubocop/cop/solidus/spree_calculator_free_shipping_deprecated.rb +7 -0
- data/lib/rubocop/cop/solidus/spree_calculator_percent_per_item_deprecated.rb +9 -1
- data/lib/rubocop/cop/solidus/spree_calculator_price_sack_deprecated.rb +7 -0
- data/lib/rubocop/cop/solidus/spree_default_credit_card_deprecated.rb +3 -4
- data/lib/rubocop/cop/solidus/spree_gateway_bogus_deprecated.rb +4 -14
- data/lib/rubocop/cop/solidus/spree_icon_deprecated.rb +3 -3
- data/lib/rubocop/cop/solidus/spree_refund_call_perform.rb +9 -2
- data/lib/rubocop/cop/solidus/spree_t_deprecated.rb +12 -4
- data/lib/rubocop/solidus/version.rb +1 -1
- data/relnotes/v0.1.2.md +1 -1
- data/relnotes/v0.1.3.md +9 -0
- data/relnotes/v0.1.4.md +5 -0
- data/rubocop-solidus.gemspec +43 -0
- data/tasks/changelog.rb +3 -3
- data/tasks/cops_documentation.rake +322 -0
- metadata +19 -11
@@ -3,35 +3,31 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Solidus
|
6
|
-
#
|
7
|
-
# `
|
8
|
-
#
|
6
|
+
# Solidus suggests a decorator module instead of `class_eval` when overriding some features.
|
7
|
+
# This cop finds any `class_eval` and asks to use a decorator module instead.
|
8
|
+
# More info: https://guides.solidus.io/customization/customizing-the-core.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
# @example EnforcedStyle: SpreeClass
|
12
|
-
# # Description of the `SpreeClass` style.
|
10
|
+
# @example
|
13
11
|
#
|
14
12
|
# # bad
|
15
13
|
# SpreeClass.class_eval do
|
16
|
-
#
|
17
|
-
# .
|
14
|
+
# # your code here
|
18
15
|
# end
|
19
16
|
#
|
20
|
-
#
|
21
17
|
# # good
|
22
|
-
# module
|
23
|
-
#
|
24
|
-
#
|
18
|
+
# module Spree
|
19
|
+
# module SpreeClassDecorator
|
20
|
+
# # your code here
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# Spree::SpreeClass.prepend self
|
25
24
|
# end
|
26
25
|
#
|
27
26
|
class ClassEvalDecorator < Base
|
28
|
-
MSG = 'Do not use `class_eval` flag. Use a decorator module instead.
|
27
|
+
MSG = 'Do not use `class_eval` flag. Use a decorator module instead. More info: https://guides.solidus.io/customization/customizing-the-core.'
|
29
28
|
|
30
|
-
# TODO: Don't call `on_send` unless the method name is in this list
|
31
|
-
# If you don't need `on_send` in the cop you created, remove it.
|
32
29
|
RESTRICT_ON_SEND = %i[class_eval].freeze
|
33
30
|
|
34
|
-
# @!method on_class_eval?(node)
|
35
31
|
def_node_matcher :on_class_eval?, <<~PATTERN
|
36
32
|
(send ($...) :class_eval)
|
37
33
|
PATTERN
|
@@ -5,6 +5,23 @@ module RuboCop
|
|
5
5
|
module Solidus
|
6
6
|
# This cop finds reimbursement_success_hooks and reimbursement_failed_hooks calls and
|
7
7
|
# asks to remove them and subscribe to reimbursement_reimbursed event instead.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# reimbursement_success_hooks.each { |h| h.call self }
|
13
|
+
# reimbursement_failed_hooks.each { |h| h.call self }
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
#
|
19
|
+
# # bad
|
20
|
+
# reimbursement_success_hooks.any?
|
21
|
+
# reimbursement_failed_hooks.any?
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
#
|
8
25
|
class ReimbursementHookDeprecated < Base
|
9
26
|
include TargetSolidusVersion
|
10
27
|
minimum_solidus_version 2.11
|
@@ -6,6 +6,13 @@ module RuboCop
|
|
6
6
|
# This cop finds Spree::Calculator::FreeShipping calls.
|
7
7
|
# This cop is needed as they have been deprecated in future version.
|
8
8
|
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# Spree::Calculator::FreeShipping
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
#
|
9
16
|
class SpreeCalculatorFreeShippingDeprecated < Base
|
10
17
|
MSG = 'Spree::Calculator::FreeShipping is deprecated.'
|
11
18
|
|
@@ -6,10 +6,18 @@ module RuboCop
|
|
6
6
|
# This cop finds Spree::Calculator::PercentPerItem calls.
|
7
7
|
# This cop is needed as they have been deprecated in future version.
|
8
8
|
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# Spree::Calculator::PercentPerItem
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# Spree::Calculator::PercentOnLineItem
|
16
|
+
#
|
9
17
|
class SpreeCalculatorPercentPerItemDeprecated < Base
|
10
18
|
extend AutoCorrector
|
11
19
|
|
12
|
-
MSG = 'Spree::Calculator::PercentPerItem is deprecated.'
|
20
|
+
MSG = 'Spree::Calculator::PercentPerItem is deprecated. Use Spree::Calculator::PercentOnLineItem instead.'
|
13
21
|
|
14
22
|
def_node_matcher :percent_per_item?, <<~PATTERN
|
15
23
|
(send (... (... :Calculator) :PercentPerItem) $_)
|
@@ -6,6 +6,13 @@ module RuboCop
|
|
6
6
|
# This cop finds Spree::Calculator::PriceSack calls.
|
7
7
|
# This cop is needed as they have been deprecated in future version.
|
8
8
|
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# Spree::Calculator::PriceSack
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
#
|
9
16
|
class SpreeCalculatorPriceSackDeprecated < Base
|
10
17
|
MSG = 'Spree::Calculator::PriceSack is deprecated.'
|
11
18
|
|
@@ -3,16 +3,16 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Solidus
|
6
|
-
# This cop finds user.default_credit_card suggest using user.wallet.default_wallet_payment_source
|
6
|
+
# This cop finds user.default_credit_card suggest using user.wallet.default_wallet_payment_source.
|
7
|
+
#
|
8
|
+
# @example
|
7
9
|
#
|
8
|
-
# @example EnforcedStyle:
|
9
10
|
# # bad
|
10
11
|
# user.default_credit_card
|
11
12
|
#
|
12
13
|
# # good
|
13
14
|
# user.wallet.default_wallet_payment_source
|
14
15
|
#
|
15
|
-
#
|
16
16
|
class SpreeDefaultCreditCardDeprecated < Base
|
17
17
|
extend AutoCorrector
|
18
18
|
include TargetSolidusVersion
|
@@ -20,7 +20,6 @@ module RuboCop
|
|
20
20
|
|
21
21
|
MSG = 'user.default_credit_card is deprecated. Please use user.wallet.default_wallet_payment_source instead.'
|
22
22
|
|
23
|
-
# @!method bad_method?(node)
|
24
23
|
def_node_matcher :default_credit_card?, <<~PATTERN
|
25
24
|
(send ... :default_credit_card)
|
26
25
|
PATTERN
|
@@ -3,29 +3,20 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Solidus
|
6
|
-
# This cop finds Spree::Gateway::Bogus calls and replaces them with the Spree::PaymentMethod::BogusCreditCard
|
6
|
+
# This cop finds Spree::Gateway::Bogus calls and replaces them with the Spree::PaymentMethod::BogusCreditCard.
|
7
7
|
# This cop is needed as the Spree::Gateway::Bogus has been deprecated in future version.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
# # bad
|
11
11
|
# Spree::Gateway::Bogus.new
|
12
|
-
#
|
13
|
-
# # good
|
14
|
-
# Spree::PaymentMethod::BogusCreditCard.new
|
15
|
-
#
|
16
|
-
# # bad
|
17
12
|
# Spree::Gateway::Bogus.create
|
18
|
-
#
|
19
|
-
# # good
|
20
|
-
# Spree::PaymentMethod::BogusCreditCard.create
|
21
|
-
#
|
22
|
-
# # bad
|
23
13
|
# Spree::Gateway::Bogus.create!
|
24
14
|
#
|
25
15
|
# # good
|
16
|
+
# Spree::PaymentMethod::BogusCreditCard.new
|
17
|
+
# Spree::PaymentMethod::BogusCreditCard.create
|
26
18
|
# Spree::PaymentMethod::BogusCreditCard.create!
|
27
19
|
#
|
28
|
-
#
|
29
20
|
class SpreeGatewayBogusDeprecated < Base
|
30
21
|
extend AutoCorrector
|
31
22
|
include TargetSolidusVersion
|
@@ -33,7 +24,6 @@ module RuboCop
|
|
33
24
|
|
34
25
|
MSG = 'Spree::Gateway::Bogus is deprecated. Please use Spree::PaymentMethod::BogusCreditCard instead.'
|
35
26
|
|
36
|
-
# @!method bad_method?(node)
|
37
27
|
def_node_matcher :bad_class?, <<~PATTERN
|
38
28
|
(send (... (... :Gateway) :Bogus) $_)
|
39
29
|
PATTERN
|
@@ -3,16 +3,16 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Solidus
|
6
|
-
# This cop finds icon helper calls and suggest using solidus_icon
|
6
|
+
# This cop finds icon helper calls and suggest using solidus_icon.
|
7
|
+
#
|
8
|
+
# @example
|
7
9
|
#
|
8
|
-
# @example EnforcedStyle:
|
9
10
|
# # bad
|
10
11
|
# helper.icon('example')
|
11
12
|
#
|
12
13
|
# # good
|
13
14
|
# helper.solidus_icon('example')
|
14
15
|
#
|
15
|
-
#
|
16
16
|
class SpreeIconDeprecated < Base
|
17
17
|
extend AutoCorrector
|
18
18
|
include TargetSolidusVersion
|
@@ -4,7 +4,15 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Solidus
|
6
6
|
# This cop finds Spree::Refund.create(your: attributes) calls and
|
7
|
-
# replaces them with the Spree::Refund.create(your: attributes, perform_after_create: false).perform! call
|
7
|
+
# replaces them with the Spree::Refund.create(your: attributes, perform_after_create: false).perform! call.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# Spree::Refund.create(your: attributes)
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# Spree::Refund.create(your: attributes, perform_after_create: false).perform!
|
8
16
|
#
|
9
17
|
class SpreeRefundCallPerform < Base
|
10
18
|
include TargetSolidusVersion
|
@@ -16,7 +24,6 @@ module RuboCop
|
|
16
24
|
|
17
25
|
RESTRICT_ON_SEND = %i[create].freeze
|
18
26
|
|
19
|
-
# @!method bad_method?(node)
|
20
27
|
def_node_matcher :create_refund?, <<~PATTERN
|
21
28
|
(send (const (const nil? :Spree) :Refund) :create ...)
|
22
29
|
PATTERN
|
@@ -3,43 +3,51 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Solidus
|
6
|
-
# This cop finds Spree.t method calls and replaces them with the I18n,t method call
|
6
|
+
# This cop finds Spree.t method calls and replaces them with the I18n,t method call.
|
7
7
|
# This cop is needed as the Spree.t version has been deprecated in future version.
|
8
8
|
#
|
9
|
+
# @example
|
10
|
+
# # Without any parameters
|
9
11
|
#
|
10
|
-
# @example EnforcedStyle: bar (default)
|
11
12
|
# # bad
|
12
13
|
# Spree.t(:bar)
|
13
14
|
#
|
14
15
|
# # good
|
15
16
|
# I18n.t(:bar, scope: :spree)
|
16
17
|
#
|
18
|
+
# @example
|
19
|
+
# # With the scope parameter
|
20
|
+
#
|
17
21
|
# # bad
|
18
22
|
# Spree.t(:bar, scope: [:city])
|
19
23
|
#
|
20
24
|
# # good
|
21
25
|
# I18n.t(:bar, scope: [:spree, :city])
|
22
26
|
#
|
27
|
+
# @example
|
28
|
+
# # With the scope and other parameters
|
29
|
+
#
|
23
30
|
# # bad
|
24
31
|
# Spree.t(:bar, scope: [:city], email: email)
|
25
32
|
#
|
26
33
|
# # good
|
27
34
|
# I18n.t(:bar, scope: [:spree, :city], email: email)
|
28
35
|
#
|
36
|
+
# @example
|
37
|
+
# # With the scope parameter as a string
|
38
|
+
#
|
29
39
|
# # bad
|
30
40
|
# Spree.t('bar', scope: 'admin.city')
|
31
41
|
#
|
32
42
|
# # good
|
33
43
|
# I18n.t('bar', scope: 'spree.admin.city')
|
34
44
|
#
|
35
|
-
#
|
36
45
|
class SpreeTDeprecated < Base
|
37
46
|
extend AutoCorrector
|
38
47
|
MSG = 'Use I18n.t instead of Spree.t which has been deprecated in future versions.'
|
39
48
|
|
40
49
|
RESTRICT_ON_SEND = %i[t].freeze
|
41
50
|
|
42
|
-
# @!method spree_t?(node)
|
43
51
|
def_node_matcher :spree_t?, <<~PATTERN
|
44
52
|
(send ($...) :t ...)
|
45
53
|
PATTERN
|
data/relnotes/v0.1.2.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
### New features
|
2
2
|
|
3
|
-
* [#45](https://github.com/
|
3
|
+
* [#45](https://github.com/solidusio/rubocop-solidus/pull/45): Fix gem version comparison. ([@MassimilianoLattanzio][])
|
4
4
|
|
5
5
|
[@MassimilianoLattanzio]: https://github.com/MassimilianoLattanzio
|
data/relnotes/v0.1.3.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
### New features
|
2
|
+
|
3
|
+
* [#47](https://github.com/solidusio/rubocop-solidus/pull/47): Remove support for old versions of ruby. ([@MassimilianoLattanzio][])
|
4
|
+
|
5
|
+
### Bug fixes
|
6
|
+
|
7
|
+
* [#48](https://github.com/solidusio/rubocop-solidus/pull/48): Fix typos in README and add instructions on how to use the changelog rake task. ([@MassimilianoLattanzio][])
|
8
|
+
|
9
|
+
[@MassimilianoLattanzio]: https://github.com/MassimilianoLattanzio
|
data/relnotes/v0.1.4.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/rubocop/solidus/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rubocop-solidus'
|
7
|
+
spec.version = RuboCop::Solidus::VERSION
|
8
|
+
spec.authors = ['piyushswain']
|
9
|
+
spec.email = ['piyush.swain3@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Automatic Solidus code style checking tool.'
|
12
|
+
spec.description = <<~DESCRIPTION
|
13
|
+
Automatic Solidus code style checking tool.
|
14
|
+
A RuboCop extension focused on enforcing Solidus best practices and coding conventions.
|
15
|
+
DESCRIPTION
|
16
|
+
spec.homepage = 'https://www.github.com/solidusio/rubocop-solidus'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
spec.required_ruby_version = '>= 2.7.0'
|
19
|
+
|
20
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
+
spec.metadata['source_code_uri'] = 'https://www.github.com/solidusio/rubocop-solidus'
|
22
|
+
spec.metadata['changelog_uri'] = 'https://www.github.com/solidusio/rubocop-solidus/blob/master/CHANGELOG.md'
|
23
|
+
spec.metadata['documentation_uri'] = 'https://www.github.com/solidusio/rubocop-solidus/blob/master/docs/cops.md'
|
24
|
+
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
29
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
spec.bindir = 'exe'
|
33
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
34
|
+
spec.require_paths = ['lib']
|
35
|
+
|
36
|
+
# Uncomment to register a new dependency of your gem
|
37
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
38
|
+
|
39
|
+
# For more information and examples about making a new gem, check out our
|
40
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
41
|
+
|
42
|
+
spec.add_runtime_dependency 'rubocop'
|
43
|
+
end
|
data/tasks/changelog.rb
CHANGED
@@ -9,7 +9,7 @@ class Changelog
|
|
9
9
|
TYPE_TO_HEADER = { new: 'New features', fix: 'Bug fixes', change: 'Changes' }.freeze
|
10
10
|
HEADER = /### (.*)/.freeze
|
11
11
|
PATH = 'CHANGELOG.md'
|
12
|
-
REF_URL = 'https://github.com/
|
12
|
+
REF_URL = 'https://github.com/solidusio/rubocop-solidus'
|
13
13
|
MAX_LENGTH = 40
|
14
14
|
CONTRIBUTOR = '[@%<user>s]: https://github.com/%<user>s'
|
15
15
|
SIGNATURE = Regexp.new(format(Regexp.escape('[@%<user>s][]'), user: '([\w-]+)'))
|
@@ -64,8 +64,8 @@ class Changelog
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def github_user
|
67
|
-
user = `git config --global
|
68
|
-
warn 'Set your username with `git config --global
|
67
|
+
user = `git config --global user.username`.chomp
|
68
|
+
warn 'Set your username with `git config --global user.username "myusernamehere"`' if user.empty?
|
69
69
|
|
70
70
|
user
|
71
71
|
end
|