Color mode

Quality

Static quality and accessibility inspection for generated HTML in Riebeckite.

日本語

Overview

qualityPlugin() runs a small set of dependency-free, regex-based rules over the HTML produced by the build and reports the findings through the shared diagnostics channel. There is no DOM, no axe-core, and no headless browser.

At the manifest stage the plugin inspects each public entry's rendered article HTML. Integrations that finish HTML generation can additionally call the exported inspectGeneratedHtml hook for final pages.

Usage

ts
import { defineConfig } from "@riebeckite/core";
import { qualityPlugin } from "@riebeckite/plugin-quality";
 
export default defineConfig({
  // ...
  plugins: [qualityPlugin({ failOn: "error" })],
});

Options

Option Type Description
ignoreRules string[] Diagnostic codes to suppress (for example "quality:empty-link-text").
a11y { enabled?: boolean } Accessibility inspection. Defaults to enabled; set enabled: false to disable every rule.
failOn "error" | "never" Throw on the first build with an error-severity diagnostic during the manifest stage. Defaults to "never".

Rules

Code Severity Description
quality:img-alt-missing warning <img> without an alt attribute. alt="" is valid for decorative images.
quality:duplicate-id error The same id value used more than once.
quality:broken-internal-anchor warning href="#foo" with no matching id="foo" in the document.
quality:heading-order warning Skipped heading levels (for example h1 → h3) or headings without any h1.
quality:empty-link-text warning <a href> with empty text and no aria-label, title, or non-empty img[alt].
quality:html-lang-missing warning <html> without a non-empty lang attribute (full documents only).
quality:table-no-header warning <table> with data cells but no <th>, scope, or headers.

API

  • qualityPlugin(options?) — plugin factory.
  • inspectHtml(html, options?) — pure function returning Diagnostic[].
  • inspectGeneratedHtml(page, options?) — pure function that inspects a final page and sets filePath to page.path.
  • RULE_CODES — the stable code identifiers.
  • Types: QualityOptions, InspectOptions.

Limitations

The scanner is regex-based, not a real DOM. It does not validate malformed markup, does not track nesting depth, and only handles well-formed, non-nested elements when pairing an open tag with its close tag. Comments and <script>/<style> contents are masked before scanning. Rules that depend on document structure (heading order, table headers) can therefore miss or misattribute findings in unusual markup.

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/quality/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # Quality
4 +
5 + Static quality and accessibility inspection for generated HTML in Riebeckite.
6 +
7 + [日本語](./quality.md)
8 +
9 + ## Overview
10 +
11 + `qualityPlugin()` runs a small set of dependency-free, regex-based rules over
12 + the HTML produced by the build and reports the findings through the shared
13 + diagnostics channel. There is no DOM, no axe-core, and no headless browser.
14 +
15 + At the manifest stage the plugin inspects each public entry's rendered article
16 + HTML. Integrations that finish HTML generation can additionally call the
17 + exported `inspectGeneratedHtml` hook for final pages.
18 +
19 + ## Usage
20 +
21 + ```ts
22 + import { defineConfig } from "@riebeckite/core";
23 + import { qualityPlugin } from "@riebeckite/plugin-quality";
24 +
25 + export default defineConfig({
26 + // ...
27 + plugins: [qualityPlugin({ failOn: "error" })],
28 + });
29 + ```
30 +
31 + ## Options
32 +
33 + | Option | Type | Description |
34 + | ------ | ---- | ----------- |
35 + | `ignoreRules` | `string[]` | Diagnostic codes to suppress (for example `"quality:empty-link-text"`). |
36 + | `a11y` | `{ enabled?: boolean }` | Accessibility inspection. Defaults to enabled; set `enabled: false` to disable every rule. |
37 + | `failOn` | `"error" \| "never"` | Throw on the first build with an error-severity diagnostic during the manifest stage. Defaults to `"never"`. |
38 +
39 + ## Rules
40 +
41 + | Code | Severity | Description |
42 + | ---- | -------- | ----------- |
43 + | `quality:img-alt-missing` | warning | `<img>` without an `alt` attribute. `alt=""` is valid for decorative images. |
44 + | `quality:duplicate-id` | error | The same `id` value used more than once. |
45 + | `quality:broken-internal-anchor` | warning | `href="#foo"` with no matching `id="foo"` in the document. |
46 + | `quality:heading-order` | warning | Skipped heading levels (for example `h1` → `h3`) or headings without any `h1`. |
47 + | `quality:empty-link-text` | warning | `<a href>` with empty text and no `aria-label`, `title`, or non-empty `img[alt]`. |
48 + | `quality:html-lang-missing` | warning | `<html>` without a non-empty `lang` attribute (full documents only). |
49 + | `quality:table-no-header` | warning | `<table>` with data cells but no `<th>`, `scope`, or `headers`. |
50 +
51 + ## API
52 +
53 + - `qualityPlugin(options?)` — plugin factory.
54 + - `inspectHtml(html, options?)` — pure function returning `Diagnostic[]`.
55 + - `inspectGeneratedHtml(page, options?)` — pure function that inspects a final
56 + page and sets `filePath` to `page.path`.
57 + - `RULE_CODES` — the stable code identifiers.
58 + - Types: `QualityOptions`, `InspectOptions`.
59 +
60 + ## Limitations
61 +
62 + The scanner is regex-based, not a real DOM. It does not validate malformed
63 + markup, does not track nesting depth, and only handles well-formed, non-nested
64 + elements when pairing an open tag with its close tag. Comments and
65 + `<script>`/`<style>` contents are masked before scanning. Rules that depend on
66 + document structure (heading order, table headers) can therefore miss or
67 + misattribute findings in unusual markup.
68 +
69 + ## See also
70 +
71 + - [Plugin guide](../reference/plugin-api.en.md)
72 +