Class: RuboCop::Cop::GraphQL::Heredoc

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/graphql/heredoc.rb

Overview

Public: Cop for enforcing non-interpolated GRAPHQL heredocs.

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



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

def autocorrect(node)
  ->(corrector) do
    corrector.replace(node.location.expression, "<<-'GRAPHQL'")
  end
end

#check_str(node) ⇒ Object



16
17
18
19
20
21
# File 'lib/rubocop/cop/graphql/heredoc.rb', line 16

def check_str(node)
  return unless node.location.is_a?(Parser::Source::Map::Heredoc)
  return unless node.location.expression.source == "<<-GRAPHQL"

  add_offense(node, :expression, "GraphQL heredocs should be quoted. <<-'GRAPHQL'")
end

#on_dstr(node) ⇒ Object



8
9
10
# File 'lib/rubocop/cop/graphql/heredoc.rb', line 8

def on_dstr(node)
  check_str(node)
end

#on_str(node) ⇒ Object



12
13
14
# File 'lib/rubocop/cop/graphql/heredoc.rb', line 12

def on_str(node)
  check_str(node)
end