Class: Ducalis::ComplexRegex

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Includes:
RuboCop::Cop::DefNode
Defined in:
lib/ducalis/cops/complex_regex.rb

Constant Summary collapse

OFFENSE =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  | It seems like this regex is a little bit complex. It's better to increase code readability by using long form with "\\x".
MESSAGE
DEFAULT_COST =
0
COMPLEX_TYPES_COSTS =
{
  quantifier: 1,
  meta: 1,
  assertion: 1,
  group: 0.5
}.freeze

Instance Method Summary collapse

Instance Method Details

#on_begin(node) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/ducalis/cops/complex_regex.rb', line 21

def on_begin(node)
  regex_using(node).each do |regex_desc|
    next if formatted?(regex_desc) || simple?(regex_desc.first)

    add_offense(regex_desc.first, :expression, OFFENSE)
  end
end