PhiaUi.TemplateLinter (phia_ui v0.1.17)

Copy Markdown View Source

Static linter that enforces the PhiaUI theming contract on component templates.

Rules

  1. No arbitrary hex colors — classes like bg-[#000] or text-[#1a2b3c] are forbidden. Use semantic tokens instead (bg-background, etc.).

  2. No hardcoded Tailwind palette classes — classes like text-zinc-900 or bg-slate-100 couple components to a specific palette, breaking dark-mode and theming. Use text-foreground, bg-card, etc.

Usage

# Check a string of class content
PhiaUi.TemplateLinter.check_content(~s(class="bg-primary text-foreground"))
# => :ok

PhiaUi.TemplateLinter.check_content(~s(class="bg-[#000] text-zinc-900"))
# => {:error, ["Forbidden hardcoded hex: bg-[#000]", ...]}

# Scan all component templates
PhiaUi.TemplateLinter.scan_templates()
# => :ok | {:error, [{file, [violation]}]}

Summary

Functions

Checks a string of template content for theming violations.

Scans all *.ex files under priv/templates/components/ and returns :ok or {:error, [{file_path, [violation]}]}.

Functions

check_content(content)

@spec check_content(String.t()) :: :ok | {:error, [String.t()]}

Checks a string of template content for theming violations.

Returns :ok or {:error, [violation_message]}.

scan_templates()

@spec scan_templates() :: :ok | {:error, [{Path.t(), [String.t()]}]}

Scans all *.ex files under priv/templates/components/ and returns :ok or {:error, [{file_path, [violation]}]}.