Module: SimpleCov::Deprecation
- Extended by:
- Deprecation
- Included in:
- Deprecation
- Defined in:
- lib/simplecov/deprecation.rb,
sig/simplecov.rbs
Overview
Emits legacy-API deprecation warnings, deduplicated by the source location that triggered them. A deprecated method called in a loop, or a config block re-evaluated once per parallel worker, otherwise repeats the same notice until stderr is unreadable. Keying on the caller location collapses those repeats while still warning separately about each distinct call site the user needs to fix (#1204).
Constant Summary collapse
- MODES =
%i[warn raise].freeze
Instance Method Summary collapse
-
#caller_location ⇒ Object
Every shipped call site is a one-level alias such as
track_files, so the frame three up from here is the user's own code. -
#emitted ⇒ Object
Parallel workers are separate processes with their own set, so each warns at most once.
-
#mode ⇒ Object
The mode lives here rather than on the configuration singleton so that
warndepends on nothing but itself. - #mode=(mode) ⇒ Object
- #reset! ⇒ Object
- #self?.caller_location ⇒ String?
- #self?.emitted ⇒ Set[String]
- #self?.mode ⇒ Symbol
- #self?.mode= ⇒ Symbol
- #self?.reset! ⇒ void
- #self?.warn ⇒ void
-
#warn(message, location: caller_location) ⇒ Object
messageis the notice without the[DEPRECATION]tag or location prefix, both of which are added here.
Instance Method Details
#caller_location ⇒ Object
Every shipped call site is a one-level alias such as track_files, so the
frame three up from here is the user's own code. Array(...) coerces a
missing backtrace to [] so .first yields nil rather than raising.
48 49 50 |
# File 'lib/simplecov/deprecation.rb', line 48 def caller_location Array(Kernel.caller(3..3)).first end |
#emitted ⇒ Object
Parallel workers are separate processes with their own set, so each warns at most once.
54 55 56 |
# File 'lib/simplecov/deprecation.rb', line 54 def emitted @emitted ||= Set.new end |
#mode ⇒ Object
The mode lives here rather than on the configuration singleton so that
warn depends on nothing but itself. SimpleCov.deprecations is the
front door that writes it, and the CLI, which loads none of the
configuration surface, can still warn.
21 22 23 |
# File 'lib/simplecov/deprecation.rb', line 21 def mode @mode ||= :warn end |
#mode=(mode) ⇒ Object
25 26 27 28 29 |
# File 'lib/simplecov/deprecation.rb', line 25 def mode=(mode) raise ConfigurationError, "deprecations takes :warn or :raise, got #{mode.inspect}" unless MODES.include?(mode) @mode = mode end |
#reset! ⇒ Object
58 59 60 61 |
# File 'lib/simplecov/deprecation.rb', line 58 def reset! @emitted = Set.new @mode = :warn end |
#self?.caller_location ⇒ String?
1696 |
# File 'sig/simplecov.rbs', line 1696
def self?.caller_location: () -> String?
|
#self?.emitted ⇒ Set[String]
1706 |
# File 'sig/simplecov.rbs', line 1706
def self?.emitted: () -> Set[String]
|
#self?.mode ⇒ Symbol
1690 |
# File 'sig/simplecov.rbs', line 1690
def self?.mode: () -> Symbol
|
#self?.mode= ⇒ Symbol
1692 |
# File 'sig/simplecov.rbs', line 1692
def self?.mode=: (Symbol mode) -> Symbol
|
#self?.reset! ⇒ void
This method returns an undefined value.
1708 |
# File 'sig/simplecov.rbs', line 1708
def self?.reset!: () -> void
|
#self?.warn ⇒ void
This method returns an undefined value.
1694 |
# File 'sig/simplecov.rbs', line 1694
def self?.warn: (String message, ?location: String?) -> void
|
#warn(message, location: caller_location) ⇒ Object
message is the notice without the [DEPRECATION] tag or location
prefix, both of which are added here. deprecations :raise turns every
deprecated API into an error before the dedup: an error is not a notice to
collapse, and a CI guard must fail on the second offender as surely as on
the first. A missing backtrace falls back to keying on the message, so it
never silently swallows every notice.
37 38 39 40 41 42 43 |
# File 'lib/simplecov/deprecation.rb', line 37 def warn(, location: caller_location) raise ConfigurationError, if mode.equal?(:raise) return unless emitted.add?(location || ) Kernel.warn "#{"#{location}: " if location}[DEPRECATION] #{}" end |