Class: RuboCop::Cop::StringLiteralCorrector

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

Overview

This autocorrects string literals

Constant Summary

Constants included from Util

Util::LITERAL_REGEX

Constants included from PathUtil

PathUtil::HIDDEN_FILE_PATTERN

Class Method Summary collapse

Methods included from Util

add_parentheses, any_descendant?, args_begin, args_end, begins_its_line?, comment_line?, comment_lines?, double_quotes_required?, escape_string, first_part_of_call_chain, indent, interpret_string_escapes, line, line_range, needs_escaping?, on_node, parentheses?, same_line?, to_string_literal, to_supported_styles, trim_string_interpolation_escape_character

Methods included from PathUtil

absolute?, glob?, hidden_dir?, hidden_file?, hidden_file_in_not_hidden_dir?, match_path?, maybe_hidden_file?, relative_path, smart_path

Class Method Details

.correct(corrector, node, style) ⇒ Object



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

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

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