Class: Uniword::Lint::BuiltinRules::RequiredStyle

Inherits:
Rule
  • Object
show all
Defined in:
lib/uniword/lint/builtin_rules/required_style.rb

Overview

Rule: required style presence. Triggers when the named style is missing from the document.

Constant Summary

Constants inherited from Rule

Rule::TYPES

Instance Attribute Summary

Attributes inherited from Rule

#name, #options, #severity

Instance Method Summary collapse

Methods inherited from Rule

#finding, register, type, types

Constructor Details

#initialize(style_id:, **rest) ⇒ RequiredStyle

Returns a new instance of RequiredStyle.

Parameters:

  • style_id (String, Array<String>)

    required styleId(s)



12
13
14
15
# File 'lib/uniword/lint/builtin_rules/required_style.rb', line 12

def initialize(style_id:, **rest)
  super(**rest)
  @required = Array(style_id)
end

Instance Method Details

#check(document) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/uniword/lint/builtin_rules/required_style.rb', line 17

def check(document)
  present = document.styles_configuration&.styles&.map(&:styleId) || []
  @required.each do |id|
    next if present.include?(id)

    yield finding(
      message: "Required style '#{id}' is missing",
      path: "styles.xml",
    )
  end
end