Sha256: c928321d659b6d6813cb97c54c5b4cb14adad0a0aaaf470c67ca52437dd29406
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
require "rubocop" module RuboCop module Cop module Style class SubclassInitialization < Base extend RuboCop::Cop::AutoCorrector ERROR_MSG = "instance_of should not be of Array" def_node_matcher :sublclass_literal, <<~PATTERN (send (const (const ... ) :MyArray ) :[] $...) PATTERN def on_send(node) return unless (expression = sublclass_literal(node)) add_offense(node, message: ERROR_MSG) do |corrector| constant_to_replace = cop_config['InitializeArrayWith'] corrector.replace(node, "#{constant_to_replace}.new(#{expression.map(&:value)})") end end end end end end # (index # (const # (const nil :ArraySpecs) :MyArray) # (int 1) # (int 2) # (int 3) # (int 4) # (int 5))) # s(:ivasgn, :@array, # s(:send, # s(:const, # s(:const, nil, :ArraySpecs), :MyArray), :[], # s(:int, 1), # s(:int, 2), # s(:int, 3), # s(:int, 4), # s(:int, 5)))
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
grizzly-rb-1.1.0 | conversion/lib/cops/subclass_initialization.rb |
grizzly-rb-1.0.0 | conversion/lib/cops/subclass_initialization.rb |