Class: GraphQL::Modernize::Rules::RedundantNullTrue

Inherits:
Base
  • Object
show all
Defined in:
lib/graphql/modernize/rules/modernize.rb

Instance Attribute Summary

Attributes inherited from Base

#offenses

Instance Method Summary collapse

Methods inherited from Base

#initialize, node_pattern, node_types, rule, #visit

Constructor Details

This class inherits a constructor from GraphQL::Modernize::Rules::Base

Instance Method Details

#on_match(node, _captures) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/graphql/modernize/rules/modernize.rb', line 42

def on_match(node, _captures)
  return unless inside?(node, :object, :interface)

  arguments = keyword_arguments(node, :null)
  return if arguments.empty?

  if arguments.length > 1
    return unless arguments.any? { |argument| argument.value.is_a?(Prism::TrueNode) }

    return add_offense(arguments.first.location, safety: :manual,
                                                 message: "Resolve duplicate `null:` options manually")
  end
  return unless arguments.first.value.is_a?(Prism::TrueNode)

  argument = arguments.first
  if dynamic_keyword_arguments?(node)
    return add_offense(argument.location, safety: :manual,
                                          message: "Review `**` expansion and resolve `null: true` manually")
  end

  add_offense(argument.location, message: "Remove the default `null: true` option") do |rw|
    rw.remove_keyword_argument(node, :null)
  end
end