Class: RuboCop::Cop::StringLiteralCorrector

Inherits:
Object
  • Object
show all
Extended by:
Util
Defined in:
lib/rubocop/cop/correctors/string_literal_corrector.rb

Overview

This auto-corrects string literals

Constant Summary

Constants included from Util

Util::ASGN_NODES, Util::CONDITIONAL_NODES, Util::EQUALS_ASGN_NODES, Util::LITERAL_REGEX, Util::LOGICAL_OPERATOR_NODES, Util::MODIFIER_NODES, Util::OPERATOR_METHODS, Util::SHORTHAND_ASGN_NODES

Class Method Summary collapse

Methods included from Util

begins_its_line?, comment_line?, double_quotes_required?, escape_string, first_part_of_call_chain, interpret_string_escapes, line_range, needs_escaping?, on_node, operator?, parentheses?, same_line?, to_string_literal, to_supported_styles, tokens

Methods included from AST::Sexp

#s

Methods included from PathUtil

absolute?, match_path?, pwd, relative_path, reset_pwd, smart_path

Class Method Details

.correct(node, style) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/correctors/string_literal_corrector.rb', line 10

def correct(node, style)
  return if node.dstr_type?

  lambda do |corrector|
    str = node.str_content
    if style == :single_quotes
      corrector.replace(node.source_range, to_string_literal(str))
    else
      corrector.replace(node.source_range, str.inspect)
    end
  end
end