Sha256: 68d008597ab439a2ac099a6fc5c055b4af9373132d61b17d9a18282370714c2e
Contents?: true
Size: 814 Bytes
Versions: 6
Compression:
Stored size: 814 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 DuplicatedKey < Cop include Duplication MSG = 'Duplicated key in hash literal.'.freeze def on_hash(node) keys = node.keys.select(&:recursive_basic_literal?) return unless duplicates?(keys) consecutive_duplicates(keys).each do |key| add_offense(key, :expression) end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems