Sha256: d822f51880b50ff58e0c9dbdc6cc1ab0ff57d7885defb6780feaa1db08932d9b

Contents?: true

Size: 1.43 KB

Versions: 16

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  class InvalidArgs < LiquidCheck
    severity :error
    category :liquid, :graphql
    doc docs_url(__FILE__)

    def on_render(node)
      add_duplicated_key_offense(node)
    end

    def on_function(node)
      add_duplicated_key_offense(node)
    end

    def on_graphql(node)
      add_duplicated_key_offense(node)

      return if node.value.inline_query

      graphql_partial = node.value.partial_name
      return unless graphql_partial.is_a?(String)

      graphql_file = platformos_app.grouped_files[GraphqlFile][graphql_partial]
      return unless graphql_file

      provided_arguments = node.value.attributes

      return if provided_arguments.include?('args')

      (provided_arguments - graphql_file.defined_arguments).each do |name|
        add_offense("Undefined argument `#{name}` provided to `#{graphql_file.relative_path}`", node:)
      end

      (graphql_file.required_arguments - provided_arguments).each do |name|
        add_offense("Required argument `#{name}` not provided to `#{graphql_file.relative_path}`", node:)
      end
    rescue GraphQL::ParseError => e
      add_offense("GraphQL Parse error triggered by `#{graphql_file.relative_path}`: #{e.message}", node:)
    end

    def add_duplicated_key_offense(node)
      node.value.duplicated_attrs.each do |duplicated_arg|
        add_offense("Duplicated argument `#{duplicated_arg}`", node:)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
platformos-check-0.4.8 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.4.7 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.4.6 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.4.5 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.4.4 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.4.3 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.4.2 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.4.1 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.4.0 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.3.3 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.3.1 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.3.0 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.2.2 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.2.1 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.2.0 lib/platformos_check/checks/invalid_args.rb
platformos-check-0.1.0 lib/platformos_check/checks/invalid_args.rb