Sha256: 757ee673dee72b9f96563622cb2e69409ca6b62b09d178f264e82f06cc8c5c6f
Contents?: true
Size: 1.25 KB
Versions: 166
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module InternalAffairs # Enforces the use of `node.lambda_or_proc?` instead of `node.lambda? || node.proc?`. # # @example # # bad # node.lambda? || node.proc? # node.proc? || node.lambda? # # # good # node.lambda_or_proc? # class LambdaOrProc < Base extend AutoCorrector MSG = 'Use `%<prefer>s`.' # @!method lambda_or_proc(node) def_node_matcher :lambda_or_proc, <<~PATTERN { (or $(send _node :lambda?) $(send _node :proc?)) (or $(send _node :proc?) $(send _node :lambda?)) (or (or _ $(send _node :lambda?)) $(send _node :proc?)) (or (or _ $(send _node :proc?)) $(send _node :lambda?)) } PATTERN def on_or(node) return unless (lhs, rhs = lambda_or_proc(node)) offense = lhs.receiver.source_range.join(rhs.source_range.end) prefer = "#{lhs.receiver.source}.lambda_or_proc?" add_offense(offense, message: format(MSG, prefer: prefer)) do |corrector| corrector.replace(offense, prefer) end end end end end end
Version data entries
166 entries across 165 versions & 17 rubygems