Class: Abqari::Audit

Inherits:
Object
  • Object
show all
Defined in:
lib/abqari/audit.rb,
lib/abqari/audit/seo.rb,
lib/abqari/audit/a11y.rb,
lib/abqari/audit/rule.rb,
lib/abqari/audit/links.rb,
lib/abqari/audit/content.rb,
lib/abqari/audit/privacy.rb,
lib/abqari/audit/performance.rb,
lib/abqari/audit/dependencies.rb

Overview

Site audit orchestrator. Each check lives in its own rule class under lib/abqari/audit/; this file is responsible for:

- Rebuilding the site (so the audit reads fresh _site/ output).
- Invoking every rule in `RULES` against shared findings list.
- Writing the markdown report at `<site>/audit/<timestamp>.md`.
- Exposing `findings` + `count(at_least:)` so `bin/audit --strict`
can gate CI on severity.

The split keeps the orchestrator under ~100 lines and lets each rule grow independently. Adding a new category is: add a file under audit/, add the class to RULES, add the category label to CATEGORIES.

Defined Under Namespace

Classes: A11y, Content, Dependencies, Links, Performance, Privacy, Rule, SEO

Constant Summary collapse

SEVERITIES =
%w[error warn info].freeze
CATEGORIES =
{
  'links'   => 'Links',
  'seo'     => 'SEO',
  'a11y'    => 'Accessibility',
  'privacy' => 'Privacy',
  'perf'    => 'Performance',
  'deps'    => 'Dependencies',
  'content' => 'Content'
}.freeze
RULES =

Rule classes, in execution order. Order matters only for the output report — findings are grouped by category, not insertion order — but Links first keeps the report scan-friendly: errors appear before warnings.

[Links, SEO, A11y, Privacy, Performance, Dependencies, Content].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Audit

Returns a new instance of Audit.



50
51
52
53
# File 'lib/abqari/audit.rb', line 50

def initialize(site)
  @site = site
  @findings = []
end

Instance Attribute Details

#findingsObject (readonly)

Returns the value of attribute findings.



48
49
50
# File 'lib/abqari/audit.rb', line 48

def findings
  @findings
end

Instance Method Details

#count(at_least: 'error') ⇒ Object

Count findings at or above the given severity. Used by bin/audit --strict to set the process exit code.



66
67
68
69
70
# File 'lib/abqari/audit.rb', line 66

def count(at_least: 'error')
  threshold = SEVERITIES.index(at_least.to_s) or
    raise ArgumentError, "unknown severity #{at_least.inspect}, expected one of #{SEVERITIES.inspect}"
  @findings.count { |f| (SEVERITIES.index(f[:severity]) || SEVERITIES.size) <= threshold }
end

#runObject



55
56
57
58
59
60
61
62
# File 'lib/abqari/audit.rb', line 55

def run
  # No syndication / webmention sending during an audit — auditing a
  # not-yet-deployed post must not broadcast it. See Site#build.
  @site.build(side_effects: false)
  RULES.each { |klass| klass.new(@site, @findings).run }
  write_report
  self
end