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/json.rb')
-rw-r--r--rubocop/cop/gitlab/json.rb18
1 files changed, 7 insertions, 11 deletions
diff --git a/rubocop/cop/gitlab/json.rb b/rubocop/cop/gitlab/json.rb
index d2ba0012ca0..56846e3c276 100644
--- a/rubocop/cop/gitlab/json.rb
+++ b/rubocop/cop/gitlab/json.rb
@@ -3,7 +3,9 @@
module RuboCop
module Cop
module Gitlab
- class Json < RuboCop::Cop::Cop
+ class Json < RuboCop::Cop::Base
+ extend RuboCop::Cop::AutoCorrector
+
MSG = <<~EOL
Avoid calling `JSON` directly. Instead, use the `Gitlab::Json`
wrapper. This allows us to alter the JSON parser being used.
@@ -14,19 +16,13 @@ module RuboCop
PATTERN
def on_send(node)
- add_offense(node) if json_node?(node)
- end
-
- def autocorrect(node)
- autocorrect_json_node(node)
- end
+ return unless json_node?(node)
- def autocorrect_json_node(node)
- _, method_name, *arg_nodes = *node
+ add_offense(node) do |corrector|
+ _, method_name, *arg_nodes = *node
- replacement = "Gitlab::Json.#{method_name}(#{arg_nodes.map(&:source).join(', ')})"
+ replacement = "Gitlab::Json.#{method_name}(#{arg_nodes.map(&:source).join(', ')})"
- lambda do |corrector|
corrector.replace(node.source_range, replacement)
end
end