Class: Kettle::Dev::MarkdownReferenceValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/kettle/dev/markdown_reference_validator.rb

Overview

Validates Markdown reference labels and local link destinations.

This deliberately validates only the small Markdown subset needed by the release gate. Available general-purpose parsers either reject reference layouts accepted by existing project changelogs or discard unresolved reference syntax, so they cannot provide these diagnostics. Keep the scanner bounded to reference definitions/usages, local destinations, and headings; it is not a general Markdown parser.

Defined Under Namespace

Classes: Issue, Report

Constant Summary collapse

FENCE_RE =

CommonMark permits at most three leading spaces before a fenced block.

/\A {0,3}(`{3,}|~{3,})/.freeze
IGNORED_PATH_PREFIXES =
%w[tmp/ .git/ spec/ test/].freeze
REFERENCE_DEFINITION_RE =
/\A {0,3}\[([^\]]+)\]:\s*(?:<([^>]+)>|(\S+))/
REFERENCE_USAGE_RE =
/!?\[([^\]]*)\]\[([^\]]*)\]/
/!?\[[^\]]*\]\((<[^>]+>|[^)]*)\)/
ATX_HEADING_RE =
/\A {0,3}\#{1,6}\s+(.+?)\s*\#*\s*\z/
SETEXT_HEADING_RE =
/\A {0,3}(=+|-+)\s*\z/

Instance Method Summary collapse

Constructor Details

#initialize(root: Dir.pwd, files: nil) ⇒ MarkdownReferenceValidator

Returns a new instance of MarkdownReferenceValidator.



29
30
31
32
# File 'lib/kettle/dev/markdown_reference_validator.rb', line 29

def initialize(root: Dir.pwd, files: nil)
  @root = File.expand_path(root)
  @files = (files || default_files).reject { |path| ignored_path?(path) }
end

Instance Method Details

#validate!Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kettle/dev/markdown_reference_validator.rb', line 34

def validate!
  documents = @files.each_with_object({}) do |path, result|
    absolute = absolute_path(path)
    result[path] = parse_document(path, absolute) if File.file?(absolute)
  end
  report = build_report(documents)
  return report if report.issues.empty?

  warn("[kettle-pre-release] Markdown reference validation failed:")
  report.issues.each do |issue|
    warn("  - #{Kettle::Dev.display_path(issue.path)}:#{issue.line}: #{issue.message}")
  end
  raise Kettle::Dev::Error, "Markdown reference validation failed (#{report.issues.size} issue(s))"
end