Sha256: caf3eb032c6da6b8756c0d000a80d2c525d79403f21177957f15ccb72cf0d678
Contents?: true
Size: 1.59 KB
Versions: 30
Compression:
Stored size: 1.59 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Lint # Emulates the following Ruby warning in Ruby 3.3. # # [source,ruby] # ---- # $ ruby -e '0.times { it }' # -e:1: warning: `it` calls without arguments will refer to the first block param in Ruby 3.4; # use it() or self.it # ---- # # `it` calls without arguments will refer to the first block param in Ruby 3.4. # So use `it()` or `self.it` to ensure compatibility. # # @example # # # bad # do_something { it } # # # good # do_something { it() } # do_something { self.it } # class ItWithoutArgumentsInBlock < Base include NodePattern::Macros MSG = '`it` calls without arguments will refer to the first block param in Ruby 3.4; ' \ 'use `it()` or `self.it`.' def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler return unless (body = node.body) return unless node.arguments.empty_and_without_delimiters? if body.send_type? && deprecated_it_method?(body) add_offense(body) else body.each_descendant(:send).each do |send_node| next unless deprecated_it_method?(send_node) add_offense(send_node) end end end def deprecated_it_method?(node) return false unless node.method?(:it) !node.receiver && node.arguments.empty? && !node.parenthesized? && !node.block_literal? end end end end end
Version data entries
30 entries across 30 versions & 7 rubygems