rubocop-petal 1.7.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/base.yml +1 -1
- data/config/default.yml +13 -0
- data/lib/rubocop/cop/rspec/chewy_strategy.rb +36 -0
- data/lib/rubocop/cop/rspec/sidekiq_perform_matcher.rb +42 -0
- data/lib/rubocop/petal/plugin.rb +30 -0
- data/lib/rubocop/petal/version.rb +1 -1
- data/lib/rubocop-petal.rb +1 -4
- metadata +32 -15
- data/lib/rubocop/petal/inject.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf2f66c07fd9f7e2d26db32b9ab5a5fc704293066bf6e8519b6fdec8cec71128
|
4
|
+
data.tar.gz: 3f4a7fef3bde079552b9bcffc43665a93422d3bf4dacda37a754540787dd4773
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70fe73e240f643f554767029a2cffbb4e298b80706c823c2dda8eccb2470da549aba51847241e68f7871aedabd6a0702f37ed97ed771c2aa703aabe6c03c9b93
|
7
|
+
data.tar.gz: 77d30ff3b03bf663b6546f3a243a90cde664a854467879e0ef3d47f2856f860eddec31ac39a8f9b723450e642f3f9f2593c1ad1cfae59baa5fea8e1b3e67e3e6
|
data/config/base.yml
CHANGED
data/config/default.yml
CHANGED
@@ -59,6 +59,12 @@ RSpec/AggregateExamples:
|
|
59
59
|
- validate_inclusion_of
|
60
60
|
- validates_exclusion_of
|
61
61
|
|
62
|
+
RSpec/ChewyStrategy:
|
63
|
+
Description: 'Prevent using Chewy strategy in tests.'
|
64
|
+
Enabled: true
|
65
|
+
Include:
|
66
|
+
- spec/**/*
|
67
|
+
|
62
68
|
RSpec/CreateListMax:
|
63
69
|
Description: 'Prevent creating to most records with `FactoryBot.create_list`.'
|
64
70
|
Enabled: true
|
@@ -73,6 +79,13 @@ RSpec/SidekiqInline:
|
|
73
79
|
Include:
|
74
80
|
- spec/**/*
|
75
81
|
|
82
|
+
RSpec/SidekiqPerformMatcher:
|
83
|
+
Description: 'Prevent using `receive(:perform_async)` in favor of rspec-sidekiq matcher'
|
84
|
+
StyleGuide: https://github.com/wspurgin/rspec-sidekiq
|
85
|
+
Enabled: true
|
86
|
+
Include:
|
87
|
+
- spec/**/*
|
88
|
+
|
76
89
|
RSpec/StubProducts:
|
77
90
|
Description: 'Suggest to use stub_products instead of veil/unveil_product.'
|
78
91
|
Enabled: true
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Prevent to change the Chewy strategy in tests.
|
7
|
+
# Setting the strategy to atomic may try to import unnecessary data
|
8
|
+
# for the test which result to a slower test suite.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# let(:user) { Chewy.strategy(:atomic) { create(:user) } }
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# let(:user) { create(:user) }
|
16
|
+
# before { UserIndex.import! user }
|
17
|
+
#
|
18
|
+
class ChewyStrategy < Base
|
19
|
+
MSG = 'Do not use Chewy.strategy in tests. Import data explicitly instead.'
|
20
|
+
RESTRICT_ON_SEND = %i[strategy].freeze
|
21
|
+
|
22
|
+
# @!method chewy_strategy?(node)
|
23
|
+
def_node_matcher :chewy_strategy?, <<~PATTERN
|
24
|
+
(send (const nil? :Chewy) :strategy ...)
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def on_send(node)
|
28
|
+
return unless chewy_strategy?(node)
|
29
|
+
|
30
|
+
add_offense(node)
|
31
|
+
end
|
32
|
+
alias on_csend on_send
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Prevent the use of `receive(:perform_async)` matcher to
|
7
|
+
# use instead rspec-sidekiq matcher like `enqueue_sidekiq_job`.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# expect(MyWorker).to receive(:perform_async).with(args)
|
12
|
+
# expect(MyWorker).to receive(:perform_in).with(5.seconds, args)
|
13
|
+
# expect(MyWorker).to receive(:perform_at).with(specific_time, args)
|
14
|
+
# expect(MyWorker).to receive(:perform_bulk)
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# expect(MyWorker).to have_enqueued_sidekiq_job.with(args)
|
18
|
+
# expect(MyWorker).to have_enqueued_sidekiq_job.in(1.seconds).with(args)
|
19
|
+
# expect(MyWorker).to have_enqueued_sidekiq_job.at(specific_time).with(args)
|
20
|
+
# expect(MyWorker).to have_enqueued_sidekiq_job
|
21
|
+
#
|
22
|
+
class SidekiqPerformMatcher < Base
|
23
|
+
MSG = 'Use `have_enqueued_sidekiq_job` instead of `receive(:perform_%s)`.'
|
24
|
+
RESTRICT_ON_SEND = %i[receive].freeze
|
25
|
+
|
26
|
+
# @!method perform_matcher?(node)
|
27
|
+
def_node_matcher :perform_matcher?, <<~PATTERN
|
28
|
+
(send nil? :receive (sym {:perform_async :perform_in :perform_at :perform_bulk}))
|
29
|
+
PATTERN
|
30
|
+
|
31
|
+
def on_send(node)
|
32
|
+
return unless perform_matcher?(node)
|
33
|
+
|
34
|
+
perform_method = node.first_argument.value.to_s.sub('perform_', '')
|
35
|
+
|
36
|
+
add_offense(node, message: format(MSG, perform_method))
|
37
|
+
end
|
38
|
+
alias on_csend on_send
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'lint_roller'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Petal
|
7
|
+
class Plugin < LintRoller::Plugin
|
8
|
+
def about
|
9
|
+
LintRoller::About.new(
|
10
|
+
name: 'rubocop-petal',
|
11
|
+
version: VERSION,
|
12
|
+
homepage: 'https://github.com/petalmd/rubocop-petal',
|
13
|
+
description: 'Petal global cops configuration'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def supported?(context)
|
18
|
+
context.engine == :rubocop
|
19
|
+
end
|
20
|
+
|
21
|
+
def rules(_context)
|
22
|
+
LintRoller::Rules.new(
|
23
|
+
type: :path,
|
24
|
+
config_format: :rubocop,
|
25
|
+
value: Pathname.new(__dir__).join('../../../config/default.yml')
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rubocop-petal.rb
CHANGED
@@ -4,8 +4,5 @@ require 'rubocop'
|
|
4
4
|
|
5
5
|
require_relative 'rubocop/petal'
|
6
6
|
require_relative 'rubocop/petal/version'
|
7
|
-
require_relative 'rubocop/petal/
|
8
|
-
|
9
|
-
RuboCop::Petal::Inject.defaults!
|
10
|
-
|
7
|
+
require_relative 'rubocop/petal/plugin'
|
11
8
|
require_relative 'rubocop/cop/petal_cops'
|
metadata
CHANGED
@@ -1,99 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-petal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Francis Bastien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lint_roller
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rubocop
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
33
|
+
version: '1.75'
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
40
|
+
version: '1.75'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rubocop-factory_bot
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2.
|
47
|
+
version: '2.27'
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '2.
|
54
|
+
version: '2.27'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rubocop-performance
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
61
|
+
version: '1.25'
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
68
|
+
version: '1.25'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rubocop-rails
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2.
|
75
|
+
version: '2.31'
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2.
|
82
|
+
version: '2.31'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rubocop-rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
89
|
+
version: '3.5'
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
96
|
+
version: '3.5'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rubocop-rspec_rails
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '2.
|
103
|
+
version: '2.31'
|
90
104
|
type: :runtime
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '2.
|
110
|
+
version: '2.31'
|
97
111
|
description:
|
98
112
|
email:
|
99
113
|
- jfbastien@petalmd.com
|
@@ -131,10 +145,12 @@ files:
|
|
131
145
|
- lib/rubocop/cop/rspec/aggregate_examples/matchers_with_side_effects.rb
|
132
146
|
- lib/rubocop/cop/rspec/aggregate_examples/metadata_helpers.rb
|
133
147
|
- lib/rubocop/cop/rspec/aggregate_examples/node_matchers.rb
|
148
|
+
- lib/rubocop/cop/rspec/chewy_strategy.rb
|
134
149
|
- lib/rubocop/cop/rspec/create_list_max.rb
|
135
150
|
- lib/rubocop/cop/rspec/json_response.rb
|
136
151
|
- lib/rubocop/cop/rspec/multiple_expectations_auto_correct.rb
|
137
152
|
- lib/rubocop/cop/rspec/sidekiq_inline.rb
|
153
|
+
- lib/rubocop/cop/rspec/sidekiq_perform_matcher.rb
|
138
154
|
- lib/rubocop/cop/rspec/stub_products.rb
|
139
155
|
- lib/rubocop/cop/sidekiq/const_argument.rb
|
140
156
|
- lib/rubocop/cop/sidekiq/date_time_argument.rb
|
@@ -144,7 +160,7 @@ files:
|
|
144
160
|
- lib/rubocop/cop/sidekiq/perform_inline.rb
|
145
161
|
- lib/rubocop/cop/sidekiq/symbol_argument.rb
|
146
162
|
- lib/rubocop/petal.rb
|
147
|
-
- lib/rubocop/petal/
|
163
|
+
- lib/rubocop/petal/plugin.rb
|
148
164
|
- lib/rubocop/petal/version.rb
|
149
165
|
homepage: https://github.com/petalmd/rubocop-petal
|
150
166
|
licenses:
|
@@ -155,6 +171,7 @@ metadata:
|
|
155
171
|
source_code_uri: https://github.com/petalmd/rubocop-petal
|
156
172
|
bug_tracker_uri: https://github.com/petalmd/rubocop-petal/issues
|
157
173
|
rubygems_mfa_required: 'true'
|
174
|
+
default_lint_roller_plugin: RuboCop::Petal::Plugin
|
158
175
|
post_install_message:
|
159
176
|
rdoc_options: []
|
160
177
|
require_paths:
|
data/lib/rubocop/petal/inject.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
|
4
|
-
# See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
|
5
|
-
module RuboCop
|
6
|
-
module Petal
|
7
|
-
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
8
|
-
# bit of our configuration.
|
9
|
-
module Inject
|
10
|
-
def self.defaults!
|
11
|
-
path = CONFIG_DEFAULT.to_s
|
12
|
-
hash = ConfigLoader.send(:load_yaml_configuration, path)
|
13
|
-
config = Config.new(hash, path).tap(&:make_excludes_absolute)
|
14
|
-
puts "configuration from #{path}" if ConfigLoader.debug?
|
15
|
-
config = ConfigLoader.merge_with_default(config, path)
|
16
|
-
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|