Module: RuboCop::Cop::StringLiteralsHelp
- Includes:
- StringHelp
- Included in:
- RuboCop::Cop::Style::StringLiterals, RuboCop::Cop::Style::StringLiteralsInInterpolation
- Defined in:
- lib/rubocop/cop/mixin/string_literals_help.rb
Overview
Common functionality for cops checking single/double quotes.
Instance Method Summary collapse
Methods included from StringHelp
#inside_interpolation?, #on_regexp, #on_str
Instance Method Details
#autocorrect(node) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rubocop/cop/mixin/string_literals_help.rb', line 20 def autocorrect(node) 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 |
#wrong_quotes?(node) ⇒ Boolean
10 11 12 13 14 15 16 17 18 |
# File 'lib/rubocop/cop/mixin/string_literals_help.rb', line 10 def wrong_quotes?(node) src = node.source return false if src.start_with?('%', '?') if style == :single_quotes !double_quotes_required?(src) else src !~ /" | \\ | \#(@|\{)/x end end |