class RuboCop::Cop::Lint::NestedPercentLiteral
}
nested_attributes: %i[name content %i[incorrectly nested]]
valid_attributes: %i[name content],
attributes = {
# yielding the array [:name, :content, :“%i[incorrectly”, :“nested]”].
# The percent literal for nested_attributes is parsed as four tokens,
# bad
@example
This cop checks for nested percent literals.
def contains_percent_literals?(node)
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
def on_array(node)
def on_array(node) process(node, *PercentLiteral::PERCENT_LITERAL_TYPES) end
def on_percent_literal(node)
def on_percent_literal(node) add_offense(node) if contains_percent_literals?(node) end
def str_content(node)
def str_content(node) if node.str_type? node.children[0] else node.children.map { |c| str_content(c) }.join end end