Class: RedQuilt::LintPass

Inherits:
Object
  • Object
show all
Defined in:
lib/red_quilt/lint_pass.rb

Overview

Optional second-pass linter. Runs AFTER InlinePass when callers pass ‘lint: true` to RedQuilt.parse / .render_html. Walks the assembled tree once and appends warnings / info diagnostics to Document#diagnostics for lint-style issues that the parser cannot reasonably detect inline (heading-level skips, empty link destinations, images without alt text, …).

Each rule is keyed by a Symbol on Diagnostic#rule so callers can filter or silence individually.

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ LintPass

Returns a new instance of LintPass.



14
15
16
17
18
# File 'lib/red_quilt/lint_pass.rb', line 14

def initialize(document)
  @document = document
  @arena = document.arena
  @diagnostics = document.diagnostics
end

Instance Method Details

#applyObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/red_quilt/lint_pass.rb', line 20

def apply
  last_heading_level = 0
  walk(@document.root_id) do |id|
    case @arena.type(id)
    when NodeType::HEADING
      level = @arena.int1(id)
      if last_heading_level.positive? && level > last_heading_level + 1
        push(:info, :heading_level_skip,
             "Heading jumps from h#{last_heading_level} to h#{level}",
             @arena.source_span(id))
      end
      last_heading_level = level
    when NodeType::LINK
      check_empty_link(id)
    when NodeType::IMAGE
      check_missing_alt(id)
    end
  end
end