class RuboCop::Cop::Lint::NestedPercentLiteral
This cop checks for nested percent literals.
@example
# bad # The percent literal for nested_attributes is parsed as four tokens, # yielding the array [:name, :content, :"%i[incorrectly", :"nested]"]. attributes = { valid_attributes: %i[name content], nested_attributes: %i[name content %i[incorrectly nested]] }
Constants
- MSG
- PERCENT_LITERAL_TYPES
The array of regular expressions representing percent literals that, if found within a percent literal expression, will cause a
NestedPercentLiteral
violation to be emitted.- REGEXES
Public Instance Methods
on_array(node)
click to toggle source
# File lib/rubocop/cop/lint/nested_percent_literal.rb, line 32 def on_array(node) process(node, *PERCENT_LITERAL_TYPES) end
on_percent_literal(node)
click to toggle source
# File lib/rubocop/cop/lint/nested_percent_literal.rb, line 36 def on_percent_literal(node) add_offense(node) if contains_percent_literals?(node) end
Private Instance Methods
contains_percent_literals?(node)
click to toggle source
# File lib/rubocop/cop/lint/nested_percent_literal.rb, line 42 def contains_percent_literals?(node) node.each_child_node.any? do |child| literal = child.children.first.to_s.scrub REGEXES.any? { |regex| literal.match(regex) } end end