Class: RuboCop::Cop::GraphQL::MaxComplexitySchema

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/graphql/max_complexity_schema.rb

Overview

Detects missing max_complexity configuration in schema files

Examples:

# good

class AppSchema < BaseSchema
  max_complexity 42
end

Constant Summary collapse

MSG =
"max_complexity should be configured for schema."

Instance Method Summary collapse

Instance Method Details

#max_complexity(node) ⇒ Object



17
18
19
# File 'lib/rubocop/cop/graphql/max_complexity_schema.rb', line 17

def_node_matcher :max_complexity, <<~PATTERN
  `(send nil? :max_complexity ...)
PATTERN

#on_class(node) ⇒ Object



23
24
25
26
27
# File 'lib/rubocop/cop/graphql/max_complexity_schema.rb', line 23

def on_class(node)
  return if ::RuboCop::GraphQL::Class.new(node).nested? || max_complexity(node)

  add_offense(node)
end