Sha256: acee2ae6263b672d828efd5534319af837125879a06e1db779dd524804393779
Contents?: true
Size: 1.39 KB
Versions: 38
Compression:
Stored size: 1.39 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Rails # Identifies top-level `HashWithIndifferentAccess`. # This has been soft-deprecated since Rails 5.1. # # @example # # bad # HashWithIndifferentAccess.new(foo: 'bar') # # # good # ActiveSupport::HashWithIndifferentAccess.new(foo: 'bar') # class TopLevelHashWithIndifferentAccess < Base extend AutoCorrector extend TargetRailsVersion minimum_target_rails_version 5.1 MSG = 'Avoid top-level `HashWithIndifferentAccess`.' # @!method top_level_hash_with_indifferent_access?(node) # @param [RuboCop::AST::ConstNode] node # @return [Boolean] def_node_matcher :top_level_hash_with_indifferent_access?, <<~PATTERN (const {nil? cbase} :HashWithIndifferentAccess) PATTERN # @param [RuboCop::AST::ConstNode] node def on_const(node) return unless top_level_hash_with_indifferent_access?(node) return if node.parent&.class_type? && node.parent.ancestors.any?(&:module_type?) add_offense(node) do |corrector| autocorrect(corrector, node) end end private def autocorrect(corrector, node) corrector.insert_before(node.location.name, 'ActiveSupport::') end end end end end
Version data entries
38 entries across 37 versions & 6 rubygems