Sha256: 3c2e5fcd7a1fd02ac7e060c1edaf75c25766316dadbc762341b87a4eb44e24b1

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

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.".freeze

        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

10 entries across 10 versions & 1 rubygems

Version Path
ezcater_rubocop-0.52.6 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-0.52.5 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-0.52.4 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-0.52.3 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-0.52.2 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-0.52.1 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-0.52.0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-0.52.0.rc0 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-0.51.8 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
ezcater_rubocop-0.51.7 lib/rubocop/cop/ezcater/require_gql_error_helpers.rb