Class: Prism::Merge::NocovNode
- Inherits:
-
Ruby::Merge::NocovNodeBase
- Object
- Ruby::Merge::NocovNodeBase
- Prism::Merge::NocovNode
- Defined in:
- lib/prism/merge/nocov_node.rb
Overview
Synthetic AST node representing a nocov block directive.
A nocov block is a pair of # :nocov: comment markers that bracket content
to be excluded from SimpleCov coverage reporting.
NocovNode implements Ast::Merge::BlockDirective and behaves like FreezeNode but with kind: :nocov and merge_policy: nil (follows file preference — nocov blocks ARE user-customizable).
Defined Under Namespace
Classes: LocationWithOffsets
Constant Summary collapse
- InvalidStructureError =
Ruby::Merge::NocovNodeBase::InvalidStructureError
- Location =
Ruby::Merge::NocovNodeBase::Location
Instance Method Summary collapse
- #inspect ⇒ String (also: #to_s)
-
#leading_comments ⇒ Array<Prism::Comment>
Leading Prism comments from the first inner node that appear BEFORE this NocovNode's opening marker line.
-
#location ⇒ LocationWithOffsets, Location
Returns a location-like object for AST node compatibility.
Instance Method Details
#inspect ⇒ String Also known as: to_s
83 84 85 |
# File 'lib/prism/merge/nocov_node.rb', line 83 def inspect "#<Prism::Merge::NocovNode lines=#{@start_line}..#{@end_line} nodes=#{@nodes.length}>" end |
#leading_comments ⇒ Array<Prism::Comment>
Leading Prism comments from the first inner node that appear BEFORE this NocovNode's opening marker line. These are comments that Prism attached to the inner node via attach_comments! and represent content logically preceding the # :nocov: block. Exposing them here lets filtered_leading_comments_for / emit_matched_template_node emit those comment lines correctly when the NocovNode is the dest_node in a merge.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/prism/merge/nocov_node.rb', line 49 def leading_comments @leading_comments ||= begin first = @nodes&.first if first.respond_to?(:location) && first.location.respond_to?(:leading_comments) first.location.leading_comments.select { |c| c.location.start_line < @start_line } else [] end end end |
#location ⇒ LocationWithOffsets, Location
Returns a location-like object for AST node compatibility. Uses byte offsets when analysis.lines is available so that TopLevelMergeRunner#node_offset_range produces comparable values with FreezeNode (which also uses byte offsets). Delegates leading_comments to self so merge emission can find pre-directive comments attached by Prism's attach_comments!.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/prism/merge/nocov_node.rb', line 67 def location @location ||= begin lines = @analysis&.lines if lines # Byte offset of first char of start_line (sum of all prior line bytes) so = lines.take(@start_line - 1).sum(&:bytesize) # Byte offset past end of end_line (sum through end_line) eo = lines.take(@end_line).sum(&:bytesize) LocationWithOffsets.new(@start_line, @end_line, so, eo, self) else Location.new(@start_line, @end_line) end end end |