Sha256: 7a8c1f1c61333a29ea7f3a830fda3b95840d6b9a74e3db0b161b6f20b04dcb5c
Contents?: true
Size: 797 Bytes
Versions: 24
Compression:
Stored size: 797 Bytes
Contents
# frozen_string_literal: true module RuboCop module Cop module Lint # This cop checks for duplicated keys in hash literals. # # This cop mirrors a warning in Ruby 2.2. # # @example # # # bad # # hash = { food: 'apple', food: 'orange' } # # @example # # # good # # hash = { food: 'apple', other_food: 'orange' } class DuplicateHashKey < Cop include Duplication MSG = 'Duplicated key in hash literal.' def on_hash(node) keys = node.keys.select(&:recursive_basic_literal?) return unless duplicates?(keys) consecutive_duplicates(keys).each do |key| add_offense(key) end end end end end end
Version data entries
24 entries across 23 versions & 5 rubygems