Sha256: 9fa8a7b7b7a7204521eec8d1f5fd08b0ec44095c1846097dec33102c19f59499

Contents?: true

Size: 1.27 KB

Versions: 58

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Ezcater
      # Enforce use of GQLErrors helpers instead of throwing
      # GraphQL::ExecutionErrors directly
      #
      # @example
      #
      #   # good
      #   GQLErrors.summary_error("An error occurred")
      #   GQLErrors.request_error("You can't access this", 401)
      #   GQLErrors.field_error("is invalid", :first_name, "First Name")
      #   GQLErrors.field_errors_for(my_model, context)
      #   GQLErrors.field_errors_for(my_model, context, summary_error: "An error occurred")
      #   GQLErrors.field_errors_for(my_model, context, field_mapping: { first: :first_name })
      #
      #   # bad
      #   GraphQL::ExecutionError.new("An error occurred")
      #   GraphQL::ExecutionError.new("You can't access this", options: { status_code: 401 })
      class RequireGqlErrorHelpers < Cop
        MSG = "Use the helpers provided by `GQLErrors` instead of raising `GraphQL::ExecutionError` directly."

        def_node_matcher :graphql_const?, <<~PATTERN
          (const (const _ :GraphQL) :ExecutionError)
        PATTERN

        def on_const(node)
          return unless graphql_const?(node)

          add_offense(node, location: :expression, message: MSG)
        end
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
ezcater_rubocop-7.0.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-6.1.1 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-6.1.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-6.0.3 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-6.0.2 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-6.0.1 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-6.0.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-5.2.1 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-5.2.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-2.5.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-5.1.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-5.0.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-4.0.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-3.0.2 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-3.0.1 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-3.0.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-2.4.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-2.3.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-2.2.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-2.1.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb