This cop checks for regexp literals and reports offenses based on how many escaped slashes there are in the regexp and on the value of the configuration parameter MaxSlashes.
# File lib/rubocop/cop/style/regexp_literal.rb, line 13 def on_regexp(node) string_parts = node.children.select { |child| child.type == :str } total_string = string_parts.map { |s| s.loc.expression.source }.join slashes = total_string.count('/') delimiter_start = node.loc.begin.source[0] if delimiter_start == '/' if slashes > max_slashes add_offense(node, :expression, error_message('')) end elsif slashes <= max_slashes add_offense(node, :expression, error_message('only ')) end configure_max(delimiter_start, slashes) if @options[:auto_gen_config] end
Generated with the Darkfish Rdoc Generator 2.