Module: SimpleCov::Deprecation

Defined in:
lib/simplecov/deprecation.rb,
sig/simplecov.rbs

Overview

Emits legacy-API deprecation warnings, deduplicated by the source location that triggered them (see issue #1204).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.emittedObject

Already-emitted dedup keys for this process. Parallel workers are separate processes with their own set, so each warns at most once.



36
37
38
# File 'lib/simplecov/deprecation.rb', line 36

def emitted
  @emitted ||= Set.new
end

.reset!Object



41
42
43
# File 'lib/simplecov/deprecation.rb', line 41

def reset!
  @emitted = Set.new
end

.warn(message, location: Array(Kernel.caller(2..2)).first) ⇒ Object

Warn about a deprecated API. message is the notice without the [DEPRECATION] tag or location prefix (both are added here).

location defaults to the caller of the deprecated method that called us — every shipped call site is a one-level alias such as track_files, so the frame two up is the user code. Pass location: explicitly when the relevant site isn't that frame (e.g. a source file and line discovered while parsing). Array(...) coerces a missing backtrace (nil) to [] so .first yields nil rather than raising — and, unlike &., adds no branch for the unreachable no-caller case to the project's 100% coverage target.



25
26
27
28
29
30
31
32
# File 'lib/simplecov/deprecation.rb', line 25

def warn(message, location: Array(Kernel.caller(2..2)).first)
  # Key on location when we have one (collapses a deprecated call in a
  # loop to a single warning); fall back to the message so a missing
  # backtrace never silently swallows every notice.
  return unless emitted.add?(location || message)

  Kernel.warn "#{"#{location}: " if location}[DEPRECATION] #{message}"
end

Instance Method Details

#self?.emittedSet[String]

Returns:

  • (Set[String])


1633
# File 'sig/simplecov.rbs', line 1633

def self?.emitted: () -> Set[String]

#self?.reset!void

This method returns an undefined value.



1636
# File 'sig/simplecov.rbs', line 1636

def self?.reset!: () -> void

#self?.warnvoid

This method returns an undefined value.

Warns about a deprecated API at most once per call-site location. message is the notice without the [DEPRECATION] tag or location prefix; location defaults to the caller of the deprecated method.

Parameters:

  • message (String)
  • location: (String, nil)


1623
# File 'sig/simplecov.rbs', line 1623

def self?.warn: (String message, ?location: String?) -> void