class RuboCop::Cop::Lint::NestedPercentLiteral
}
nested_attributes: [:name, :content, [:incorrectly, :nested]]
valid_attributes: %i[name content],
attributes = {
}
nested_attributes: [:name, :content, %i[incorrectly nested]]
valid_attributes: %i[name content],
attributes = {
# Neither is incompatible with the bad case, but probably the intended code.
# good
}
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
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, *PERCENT_LITERAL_TYPES) end
def on_percent_literal(node)
def on_percent_literal(node) add_offense(node) if contains_percent_literals?(node) end