Class: SimpleCov::Sorbet::IgnoredRanges
- Inherits:
-
ASTTransform::AbstractAnalysis
- Object
- ASTTransform::AbstractAnalysis
- SimpleCov::Sorbet::IgnoredRanges
- Extended by:
- T::Sig
- Defined in:
- lib/simplecov/sorbet/ignored_ranges.rb
Overview
Read-only analysis pass collecting the line ranges of type-level Sorbet constructs coverage should ignore. Detection is purely syntactic — this gem never loads Sorbet's type system. Three constructs are collected:
T.type_aliasblocks: sorbet-runtime resolves aliases lazily and collection checks are shallow, so a multi-line alias body never executes and reads as a permanent coverage miss.sigblocks (bare or with a receiver, e.g.T::Sig::WithoutRuntime.sig): sigs are type metadata whose correctnesssrb tcowns; coverage should measure behavior. Only multi-line blocks are collected — a single-linesig { ... }occupies the send's own line, which executes at load.T.absurdsends: unreachable by definition when exhaustiveness holds, so in correct code the line is a permanent coverage miss.
Constant Summary collapse
- T_RECEIVERS =
Structural patterns for the
Treceiver (node equality ignores source locations):Tand its explicit top-level form::T. T.let( [ s(:const, nil, :T), s(:const, s(:cbase), :T), ].freeze, T::Array[Parser::AST::Node], )
Instance Attribute Summary collapse
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
Instance Method Summary collapse
-
#initialize ⇒ IgnoredRanges
constructor
A new instance of IgnoredRanges.
- #on_block(node) ⇒ Object
- #on_send(node) ⇒ Object
Constructor Details
#initialize ⇒ IgnoredRanges
Returns a new instance of IgnoredRanges.
34 35 36 37 |
# File 'lib/simplecov/sorbet/ignored_ranges.rb', line 34 def initialize @ranges = T.let([], T::Array[T::Range[Integer]]) super end |
Instance Attribute Details
#ranges ⇒ Object (readonly)
Returns the value of attribute ranges.
31 32 33 |
# File 'lib/simplecov/sorbet/ignored_ranges.rb', line 31 def ranges @ranges end |
Instance Method Details
#on_block(node) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/simplecov/sorbet/ignored_ranges.rb', line 58 def on_block(node) receiver, method_name = node.children.first.children range = line_range(node) case method_name when :type_alias @ranges << range if T_RECEIVERS.include?(receiver) when :sig # Any receiver qualifies: bare sig blocks and forms like T::Sig::WithoutRuntime.sig are all sigs. A # non-Sorbet DSL also named `sig` would be over-matched, an accepted risk documented in the README. @ranges << range if range.first < range.last end super end |
#on_send(node) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/simplecov/sorbet/ignored_ranges.rb', line 45 def on_send(node) receiver, method_name = node.children @ranges << line_range(node) if method_name == :absurd && T_RECEIVERS.include?(receiver) super end |