Class: Rubocop::Cop::StringLiterals
- Defined in:
- lib/rubocop/cop/string_literals.rb
Constant Summary collapse
- ERROR_MESSAGE =
"Prefer single-quoted strings when you don't need " + 'string interpolation or special symbols.'
Instance Attribute Summary
Attributes inherited from Cop
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, enabled?, #has_report?, inherited, #initialize
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#inspect(file, source, tokens, sexp) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rubocop/cop/string_literals.rb', line 9 def inspect(file, source, tokens, sexp) state = :outside tokens.each do |t| state = case [state, t.type] when [:outside, :on_tstring_beg] :double_quote if t.text == '"' when [:double_quote, :on_tstring_content] :valid_double_quote if t.text =~ /'|\\[ntrx]/ when [:double_quote, :on_embexpr_beg] :embedded_expression when [:double_quote, :on_tstring_end] add_offence(:convention, t.pos.lineno, ERROR_MESSAGE) :outside when [:embedded_expression, :on_rbrace] :valid_double_quote when [:valid_double_quote, :on_tstring_end] :outside end || state end end |