<commit_before># frozen_string_literal: true
module GraphQL
  module StaticValidation
    class VariableUsagesAreAllowed
      include GraphQL::StaticValidation::Message::MessageHelper

      def validate(context)
        # holds { name => ast_node } pairs
        declared_variables = {}
        context.visitor[GraphQL::Language::Nodes::OperationDefinition] << ->(node, parent) {
          declared_variables = node.variables.each_with_object({}) { |var, memo| memo[var.name] = var }
        }

        context.visitor[GraphQL::Language::Nodes::Argument] << ->(node, parent) {
          node_values = Array.wrap(node.value)
          return if !(node_values.all? { |value| value.is_a? GraphQL::Language::Nodes::VariableIdentifier })

          arguments = nil
          case parent
          when GraphQL::Language::Nodes::Field
            arguments = context.field_definition.arguments
          when GraphQL::Language::Nodes::Directive
            arguments = context.directive_definition.arguments
          when GraphQL::Language::Nodes::InputObject
            arg_type = context.argument_definition.type.unwrap
            if arg_type.is_a?(GraphQL::InputObjectType)
              arguments = arg_type.input_fields
            end
          else
            raise("Unexpected argument parent: #{parent}")<commit_msg>fix robert test<commit_after># frozen_string_literal: true
module GraphQL
  module StaticValidation
    class VariableUsagesAreAllowed
      include GraphQL::StaticValidation::Message::MessageHelper

      def validate(context)
        # holds { name => ast_node } pairs
        declared_variables = {}
        context.visitor[GraphQL::Language::Nodes::OperationDefinition] << ->(node, parent) {
          declared_variables = node.variables.each_with_object({}) { |var, memo| memo[var.name] = var }
        }

        context.visitor[GraphQL::Language::Nodes::Argument] << ->(node, parent) {
          node_values = Array.wrap(node.value).select { |value| value.is_a? GraphQL::Language::Nodes::VariableIdentifier }
          return if node_values.none?

          arguments = nil
          case parent
          when GraphQL::Language::Nodes::Field
            arguments = context.field_definition.arguments
          when GraphQL::Language::Nodes::Directive
            arguments = context.directive_definition.arguments
          when GraphQL::Language::Nodes::InputObject
            arg_type = context.argument_definition.type.unwrap
            if arg_type.is_a?(GraphQL::InputObjectType)
              arguments = arg_type.input_fields
            end
          else
            raise("Unexpected argument parent: #{parent}")
{'fraction_non_alphanumeric': 0.10387655250282274, 'fraction_numerical': 0.0, 'mean_word_length': 2.8521739130434782, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2404480', 'n_tokens_mistral': 672, 'n_tokens_neox': 674, 'n_words': 129}