Class: Kettle::Dev::MarkdownReferenceValidator
- Inherits:
-
Object
- Object
- Kettle::Dev::MarkdownReferenceValidator
- Defined in:
- lib/kettle/dev/markdown_reference_validator.rb
Overview
Validates Markdown reference labels and local link destinations.
This is intentionally a small source scanner rather than a second Markdown rendering pipeline. The release gate needs reference integrity and local anchor checks, while the existing Markdown merge/parser dependencies are not runtime dependencies of kettle-dev.
Defined Under Namespace
Constant Summary collapse
- FENCE_RE =
/\A\s*(`{3,}|~{3,})/.freeze
- IGNORED_PATH_PREFIXES =
%w[tmp/ .git/ spec/ test/].freeze
- REFERENCE_DEFINITION_RE =
/\A {0,3}\[([^\]]+)\]:\s*(?:<([^>]+)>|(\S+))/- REFERENCE_USAGE_RE =
/!?\[([^\]]*)\]\[([^\]]*)\]/- INLINE_LINK_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
-
#initialize(root: Dir.pwd, files: nil) ⇒ MarkdownReferenceValidator
constructor
A new instance of MarkdownReferenceValidator.
- #validate! ⇒ Object
Constructor Details
#initialize(root: Dir.pwd, files: nil) ⇒ MarkdownReferenceValidator
Returns a new instance of MarkdownReferenceValidator.
26 27 28 29 |
# File 'lib/kettle/dev/markdown_reference_validator.rb', line 26 def initialize(root: Dir.pwd, files: nil) @root = File.(root) @files = (files || default_files).reject { |path| ignored_path?(path) } end |
Instance Method Details
#validate! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kettle/dev/markdown_reference_validator.rb', line 31 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.}") end raise Kettle::Dev::Error, "Markdown reference validation failed (#{report.issues.size} issue(s))" end |