Module: RuboCop::GraphQL::Heredoc

Included in:
Cop::GraphQL::FieldDefinitions, Cop::GraphQL::MultipleFieldDefinitions
Defined in:
lib/rubocop/graphql/heredoc.rb

Instance Method Summary collapse

Instance Method Details

#heredoc?(node) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/rubocop/graphql/heredoc.rb', line 6

def heredoc?(node)
  (node.str_type? || node.dstr_type?) && node.heredoc?
end

#range_including_heredoc(node) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubocop/graphql/heredoc.rb', line 10

def range_including_heredoc(node)
  field = RuboCop::GraphQL::Field.new(node)
  last_heredoc = field.kwargs.instance_variable_get(:@nodes).reverse.find do |kwarg|
                   heredoc?(kwarg.value)
                 end&.value

  range = node.source_range
  range = range.join(last_heredoc.loc.heredoc_end) if last_heredoc

  range_by_whole_lines(range)
end