Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 1.72 KB

functionality.md

File metadata and controls

36 lines (27 loc) · 1.72 KB

Functionality & Features

MermaidGuard operates on three main pillars: Scanning, Validation, and Autofix.

1. File Scanning

The tool accepts glob patterns (defaults to **/*.md) to find Markdown files. It parses the Markdown AST using unified/remark to locate code blocks tagged with mermaid.

2. Validation Engine

Each found Mermaid diagram is passed to the Engine, which executes a set of rules.

Syntax Validation

  • Rule ID: syntax/valid-mermaid
  • Description: Compiles the diagram using the internal Mermaid library to ensure it is syntactically valid.
  • Behavior: If compilation fails, an error diagnostic is reported with the line/column of the syntax error.

Accessibility (A11y) Validation

MermaidGuard enforces WCAG standards by checking for accessibility tags in diagrams.

  • Rule: accessibility/title-required - Checks if the diagram has a title (e.g., accTitle: ...).
  • Rule: accessibility/desc-required - Checks if the diagram has a description (e.g., accDescr: ...).

3. Autofix System

When run with --fix, the Fixer module processes diagnostics that contain a fix payload.

  • How it works:
    1. The Linter identifies missing A11y tags.
    2. The Rule generates a Diagnostic with a fix object containing the text to insert (e.g., default accTitle).
    3. The Fixer applies these edits to the source string.
    4. The CLI writes the modified content back to the disk.

Note: Syntax errors are generally NOT auto-fixable as they vary wildly in cause.

4. Reporting

Diagnostics are output to the console with:

  • Severity: Error (Red), Warning (Yellow), Info (Blue).
  • Location: Line and Column number.
  • Rule ID: The ID of the rule that triggered the diagnostic.