diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-24 15:11:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-24 15:11:34 +0300 |
commit | d5f67e75b6ef8ebc1b304589005ccd91ea6674ff (patch) | |
tree | 8c9f80ba2df2e7d50cb4a413c4a591605c78ba6a /rubocop | |
parent | fda0e422a7804d541454d86b50113645d8d516f8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/gitlab/json.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/rubocop/cop/gitlab/json.rb b/rubocop/cop/gitlab/json.rb index 3ccb22aacf2..32bfdd9bfdc 100644 --- a/rubocop/cop/gitlab/json.rb +++ b/rubocop/cop/gitlab/json.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../../../lib/gitlab/json' - module RuboCop module Cop module Gitlab @@ -12,6 +10,8 @@ module RuboCop Prefer `Gitlab::Json` over calling `JSON` or `to_json` directly. See https://docs.gitlab.com/ee/development/json.html EOL + AVAILABLE_METHODS = %i[parse parse! load decode dump generate encode pretty_generate].to_set.freeze + def_node_matcher :json_node?, <<~PATTERN (send (const {nil? | (const nil? :ActiveSupport)} :JSON) $_ $...) PATTERN @@ -37,12 +37,12 @@ module RuboCop method_name, arg_nodes = json_node?(node) # Only match if the method is implemented by Gitlab::Json - if method_name && ::Gitlab::Json.methods(false).include?(method_name) + if method_name && AVAILABLE_METHODS.include?(method_name) return [method_name, arg_nodes.map(&:source).join(', ')] end receiver = to_json_call?(node) - return [:generate, receiver.source] if receiver + return [:dump, receiver.source] if receiver nil end |