Sha256: 7f116dd7ba342edc3294604ad023e52964ea9166dc5de87630ba11d0686f052f
Contents?: true
Size: 824 Bytes
Versions: 5
Compression:
Stored size: 824 Bytes
Contents
# encoding: utf-8 module Rubocop module Cop module Style # This cop checks for array literals made up of symbols # that are not using the %i() syntax. # # This check makes sense only on Ruby 2.0+. class SymbolArray < Cop MSG = 'Use %i or %I for array of symbols.' def on_array(node) # %i and %I were introduced in Ruby 2.0 unless RUBY_VERSION < '2.0.0' return unless node.loc.begin && node.loc.begin.is?('[') array_elems = node.children # no need to check empty arrays return unless array_elems && array_elems.size > 1 symbol_array = array_elems.all? { |e| e.type == :sym } convention(node, :expression) if symbol_array end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems