blob: 78e3ba223b0a955352ee99e0ab26c4644b5eec72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# This cop checks for `Sidekiq::Testing.server_middleware`
# usage in specs.
#
# @example
#
# # bad
# Sidekiq::Testing.server_middleware do |chain|
# chain.add(MyMiddlewareUnderTest)
# end
#
#
# # good
# with_custom_sidekiq_middleware do |chain|
# chain.add(MyMiddlewareUnderTest)
# end
#
#
class ModifySidekiqMiddleware < RuboCop::Cop::Base
extend RuboCop::Cop::AutoCorrector
MSG = <<~MSG
Don't modify global sidekiq middleware, use the `#with_sidekiq_server_middleware`
helper instead
MSG
def_node_search :modifies_sidekiq_middleware?, <<~PATTERN
(send
(const
(const nil? :Sidekiq) :Testing) :server_middleware)
PATTERN
def on_send(node)
return unless modifies_sidekiq_middleware?(node)
add_offense(node) do |corrector|
corrector.replace(node.loc.expression,
'with_sidekiq_server_middleware')
end
end
end
end
end
end
|