diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /rubocop/cop/gitlab/json.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'rubocop/cop/gitlab/json.rb')
-rw-r--r-- | rubocop/cop/gitlab/json.rb | 18 |
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 |