Class: Rubocop::Cop::Style::RegexpLiteral
- Defined in:
- lib/rubocop/cop/style/regexp_literal.rb
Overview
This cop checks for regexp literals and reports offences based on how many escaped slashes there are in the regexp and on the value of the configuration parameter MaxSlashes.
Constant Summary
Constants inherited from Cop
Instance Attribute Summary
Attributes inherited from Cop
#config, #corrections, #offences, #processed_source
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, all, #autocorrect?, #autocorrect_action, #convention, #cop_config, #cop_name, cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, rails?, style?, #warning
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#max_slashes ⇒ Object
21 22 23 |
# File 'lib/rubocop/cop/style/regexp_literal.rb', line 21 def max_slashes cop_config['MaxSlashes'] end |
#on_regexp(node) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rubocop/cop/style/regexp_literal.rb', line 10 def on_regexp(node) slashes = node.loc.expression.source.count('/') msg = if node.loc.begin.is?('/') slashes -= 2 # subtract delimiters ('') if slashes > max_slashes else ('only ') if slashes <= max_slashes end convention(node, :expression, msg) if msg end |