Rbtz.CredoChecks.Design.RawSvgInHeex (rbtz_credo_checks v0.9.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of normal and works with any version of Elixir.

Explanation

Forbids raw <svg> tags in HEEx templates.

Icons should come from a shared icon function component (for example <.icon name="search" />) rather than inline SVG markup. The component approach keeps icon naming consistent, supports compile-time icon-set verification, and avoids copy-pasting raw SVG across files.

The check inspects every ~H sigil and every .heex template referenced via embed_templates. Detection is line-by-line: a <svg whose first attribute sits on the next line is not flagged.

Bad

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <path d="..." />
</svg>

Good

<.icon name="search" />

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.