Sha256: 89f550532d2b39888d35b689bd3e98fbf6f92afdb929f6be8de894d0202262bd
Contents?: true
Size: 1.2 KB
Versions: 3
Compression:
Stored size: 1.2 KB
Contents
# encoding: utf-8 module Rubocop module Cop class EmptyLiteral < Cop ARR_MSG = 'Use array literal [] instead of Array.new.' HASH_MSG = 'Use hash literal {} instead of Hash.new.' STR_MSG = "Use string literal '' instead of String.new." # Empty array node # # (send # (const nil :Array) :new) ARRAY_NODE = s(:send, s(:const, nil, :Array), :new) # Empty hash node # # (send # (const nil :Hash) :new) HASH_NODE = s(:send, s(:const, nil, :Hash), :new) # Empty string node # # (send # (const nil :String) :new) STR_NODE = s(:send, s(:const, nil, :String), :new) def on_send(node) case node when ARRAY_NODE add_offence(:convention, node.loc.line, ARR_MSG) when HASH_NODE add_offence(:convention, node.loc.line, HASH_MSG) when STR_NODE add_offence(:convention, node.loc.line, STR_MSG) end end # TODO Check block contents as well alias_method :on_block, :ignore_node end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.8.3 | lib/rubocop/cop/empty_literal.rb |
rubocop-0.8.2 | lib/rubocop/cop/empty_literal.rb |
rubocop-0.8.1 | lib/rubocop/cop/empty_literal.rb |