Sha256: 2695d1d77b1e5461e4526fc01bcaf866542e020deb03796a94de163f4b1c161b
Contents?: true
Size: 1.45 KB
Versions: 185
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module InternalAffairs # Check for useless `RESTRICT_ON_SEND`. # # @example # # bad # class FooCop # RESTRICT_ON_SEND = %i[bad_method].freeze # end # # # good # class FooCop # RESTRICT_ON_SEND = %i[bad_method].freeze # def on_send(node) # # ... # end # end # # # good # class FooCop # RESTRICT_ON_SEND = %i[bad_method].freeze # def after_send(node) # # ... # end # end # class UselessRestrictOnSend < Base extend AutoCorrector MSG = 'Useless `RESTRICT_ON_SEND` is defined.' # @!method defined_send_callback?(node) def_node_search :defined_send_callback?, <<~PATTERN { (def {:on_send :after_send} ...) (alias (sym {:on_send :after_send}) _source ...) (send nil? :alias_method {(sym {:on_send :after_send}) (str {"on_send" "after_send"})} _source ...) } PATTERN def on_casgn(node) return if !restrict_on_send?(node) || defined_send_callback?(node.parent) add_offense(node) do |corrector| corrector.remove(node) end end private def restrict_on_send?(node) node.name == :RESTRICT_ON_SEND end end end end end
Version data entries
185 entries across 180 versions & 18 rubygems