Class: Rubocop::Cop::PercentR

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/percent_r.rb

Constant Summary collapse

ERROR_MESSAGE =
'Use %r only for regular expressions matching more ' +
"than one '/' character."

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, cop_name, #has_report?, inherited, #initialize, #name

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
# File 'lib/rubocop/cop/percent_r.rb', line 9

def inspect(file, source, tokens, sexp)
  tokens.each_cons(2) do |t1, t2|
    if t1.type == :on_regexp_beg && t1.text =~ /^%r/ &&
        t2.text !~ %r(/.*/)
      add_offence(:convention, t1.pos.lineno, ERROR_MESSAGE)
    end
  end
end