module RuboCop::Cop::ArraySyntax

Common code for ordinary arrays with [] that can be written with % syntax.

Public Instance Methods

bracketed_array_of?(element_type, node) click to toggle source
# File lib/rubocop/cop/mixin/array_syntax.rb, line 8
def bracketed_array_of?(element_type, node)
  return false unless square_brackets?(node)

  array_elems = node.children

  # no need to check empty arrays
  return false unless array_elems && array_elems.size > 1

  array_elems.all? { |e| e.type == element_type }
end
square_brackets?(node) click to toggle source
# File lib/rubocop/cop/mixin/array_syntax.rb, line 19
def square_brackets?(node)
  node.loc.begin && node.loc.begin.is?('[')
end