Class: Docbook::Services::Linter

Inherits:
Object
  • Object
show all
Defined in:
lib/docbook/services/linter.rb

Overview

Lightweight lint checks for DocBook documents.

Checks for common issues without requiring full RELAX NG validation: duplicate IDs, broken cross-references, missing images, empty sections.

Usage: linter = Docbook::Services::Linter.new(parsed_doc) result = linter.check(strict: true) result.errors # => [{ message: "...", location: "..." }] result.warnings # => [{ message: "...", location: "..." }]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, input_path: nil) ⇒ Linter

Returns a new instance of Linter.

Parameters:



21
22
23
24
25
26
# File 'lib/docbook/services/linter.rb', line 21

def initialize(document, input_path: nil)
  @document = document
  @input_path = input_path
  @errors = []
  @warnings = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



17
18
19
# File 'lib/docbook/services/linter.rb', line 17

def errors
  @errors
end

#warningsObject (readonly)

Returns the value of attribute warnings.



17
18
19
# File 'lib/docbook/services/linter.rb', line 17

def warnings
  @warnings
end

Instance Method Details

#check(strict: false) ⇒ self

Run lint checks on the document.

Parameters:

  • strict (Boolean) (defaults to: false)

    enable strict mode (broken xrefs, missing images)

Returns:

  • (self)


31
32
33
34
35
36
37
38
39
# File 'lib/docbook/services/linter.rb', line 31

def check(strict: false)
  check_duplicate_ids
  check_empty_elements
  if strict
    check_broken_xrefs
    check_missing_images
  end
  self
end

#ok?Boolean

Returns true if no errors were found.

Returns:

  • (Boolean)

    true if no errors were found



42
43
44
# File 'lib/docbook/services/linter.rb', line 42

def ok?
  @errors.empty?
end