Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'rubocop/cop/gitlab/httparty.rb')
-rw-r--r--rubocop/cop/gitlab/httparty.rb41
1 files changed, 15 insertions, 26 deletions
diff --git a/rubocop/cop/gitlab/httparty.rb b/rubocop/cop/gitlab/httparty.rb
index 20f0c381e11..f57c605ce91 100644
--- a/rubocop/cop/gitlab/httparty.rb
+++ b/rubocop/cop/gitlab/httparty.rb
@@ -3,7 +3,9 @@
module RuboCop
module Cop
module Gitlab
- class HTTParty < RuboCop::Cop::Cop
+ class HTTParty < RuboCop::Cop::Base
+ extend RuboCop::Cop::AutoCorrector
+
MSG_SEND = <<~EOL
Avoid calling `HTTParty` directly. Instead, use the Gitlab::HTTP
wrapper. To allow request to localhost or the private network set
@@ -25,31 +27,18 @@ module RuboCop
PATTERN
def on_send(node)
- add_offense(node, location: :expression, message: MSG_SEND) if httparty_node?(node)
- add_offense(node, location: :expression, message: MSG_INCLUDE) if includes_httparty?(node)
- end
-
- def autocorrect(node)
- if includes_httparty?(node)
- autocorrect_includes_httparty(node)
- else
- autocorrect_httparty_node(node)
- end
- end
-
- def autocorrect_includes_httparty(node)
- lambda do |corrector|
- corrector.remove(node.source_range)
- end
- end
-
- def autocorrect_httparty_node(node)
- _, method_name, *arg_nodes = *node
-
- replacement = "Gitlab::HTTP.#{method_name}(#{arg_nodes.map(&:source).join(', ')})"
-
- lambda do |corrector|
- corrector.replace(node.source_range, replacement)
+ if httparty_node?(node)
+ add_offense(node, message: MSG_SEND) do |corrector|
+ _, method_name, *arg_nodes = *node
+
+ replacement = "Gitlab::HTTP.#{method_name}(#{arg_nodes.map(&:source).join(', ')})"
+
+ corrector.replace(node.source_range, replacement)
+ end
+ elsif includes_httparty?(node)
+ add_offense(node, message: MSG_INCLUDE) do |corrector|
+ corrector.remove(node.source_range)
+ end
end
end
end