Class: SimpleCov::Formatter::AIFormatter::MarkdownBuilder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/simplecov-ai/markdown_builder.rb,
lib/simplecov-ai/markdown_builder/inline_code.rb,
lib/simplecov-ai/markdown_builder/decode_guard.rb,
lib/simplecov-ai/markdown_builder/skip_regions.rb,
lib/simplecov-ai/markdown_builder/source_lines.rb,
lib/simplecov-ai/markdown_builder/deficit_group.rb,
lib/simplecov-ai/markdown_builder/report_budget.rb,
lib/simplecov-ai/markdown_builder/section_writer.rb,
lib/simplecov-ai/markdown_builder/branch_enricher.rb,
lib/simplecov-ai/markdown_builder/bypass_compiler.rb,
lib/simplecov-ai/markdown_builder/deficit_grouper.rb,
lib/simplecov-ai/markdown_builder/deficit_compiler.rb,
lib/simplecov-ai/markdown_builder/deficit_formatter.rb,
lib/simplecov-ai/markdown_builder/snippet_formatter.rb

Overview

Responsible for compiling static text representations from evaluated coverage metrics: the telemetry header, the deficit and bypass sections written through a single size budget, and the closing truncation notice when that budget ran out.

Defined Under Namespace

Modules: DecodeGuard, InlineCode, SkipRegions, SnippetFormatter, SourceLines Classes: BranchEnricher, BypassCompiler, DeficitCompiler, DeficitFormatter, DeficitGroup, DeficitGrouper, MethodDeficit, ReportBudget, SectionWriter

Constant Summary collapse

STATUS_PASSED =

Text representation for a passed coverage check

T.let('PASSED', String)
STATUS_FAILED =

Text representation for a failed coverage check

T.let('FAILED', String)
LINE_DISABLED_LABEL =

Line-coverage label shown when line coverage was not enabled for the run (SimpleCov

1.0 allows a branch- or method-only run)

T.let('N/A (line coverage not enabled)', String)
BRANCH_DISABLED_LABEL =

Branch-coverage label shown when branch coverage was not enabled for the run

T.let('N/A (branch coverage not enabled)', String)
UNDECODABLE_LABEL =

Label shown for a figure SimpleCov could not compute from a corrupt resultset

T.let('N/A (coverage data could not be decoded)', String)
UNDECODABLE_PERCENT =

Stands in for a figure SimpleCov raised on while decoding: not a number, so it never compares as perfect and the status reads FAILED

T.let(Float::NAN, Float)
PERCENT_TEMPLATE =

Percentages are printed with one decimal, floored (see #figure_label)

T.let('%.1f%%', String)
HEADER_TEMPLATE =

Template for the report header; the method line is empty unless SimpleCov measured method coverage, keeping the header byte-identical for every other run.

T.let(
  "# AI Coverage Digest\n" \
  "**Status:** %<status>s\n" \
  "**Global Line Coverage:** %<line>s\n" \
  "**Global Branch Coverage:** %<branch>s\n" \
  '%<method_line>s' \
  "**Generated At:** %<time>s (Local Timezone)\n",
  String
)
METHOD_COVERAGE_LINE =

Header line for SimpleCov >= 1.0 method coverage (enable_coverage :method)

T.let("**Global Method Coverage:** %<method>s\n", String)

Instance Method Summary collapse

Constructor Details

#initialize(coverage_metrics, config) ⇒ MarkdownBuilder

Returns a new instance of MarkdownBuilder.



66
67
68
69
70
71
# File 'lib/simplecov-ai/markdown_builder.rb', line 66

def initialize(coverage_metrics, config)
  @coverage_metrics = T.let(coverage_metrics, SimpleCov::Result)
  @config = T.let(config, Configuration)
  @buffer = T.let(StringIO.new, StringIO)
  @ast_cache = T.let({}, T::Hash[String, T.nilable(T::Array[ASTResolver::SemanticNode])])
end

Instance Method Details

#buildObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/simplecov-ai/markdown_builder.rb', line 79

def build
  budget = ReportBudget.new(@buffer, @config.max_file_size_kb, @coverage_metrics.files.size)
  budget.write(header)
  omitted_deficit_files = DeficitCompiler.new(@coverage_metrics, @config, self).write_deficits(budget)
  omitted_bypass_files = write_bypasses(budget)
  if omitted_deficit_files.positive? || omitted_bypass_files.positive?
    budget.write_notice(omitted_deficit_files, omitted_bypass_files)
  end
  @buffer.string
end

#try_resolve_ast(filename) ⇒ Object



95
96
97
# File 'lib/simplecov-ai/markdown_builder.rb', line 95

def try_resolve_ast(filename)
  @ast_cache.fetch(filename) { @ast_cache[filename] = resolve_nodes(filename) }
end