OptimumCredo.HeexCheck (OptimumCredo v0.5.0)
View SourceRuns the HEEx-capable OptimumCredo checks over standalone .heex files.
Stock Credo parses every selected file as Elixir and drops .heex files as invalid, so the
checks below never see them in a normal mix credo run. This module reads each file as text,
builds a Credo.SourceFile with Credo.SourceFile.parse/2 and hands it straight to the
check's run/2. The parse attempt populates Credo's source cache; these checks inspect
the original template text even when Credo marks it invalid. No template code is evaluated.
Checks (selectable by --checks, in snake_case, CamelCase or fully qualified form):
HardcodedAssetPath(params:prefixes)HiddenIdInput(params:allowed_fields)EventNameSnakeCase(params:allowed_events)
Options for run/2
:checks- list of check names. Default: all three.:exclude- list of paths or globs removed from the matched files (a directory excludes everything below it).:prefixes,:allowed_fields,:allowed_events- lists of strings passed to the matching check.
Files
paths entries may be files (must end in .heex), directories (searched recursively for
*.heex) or globs (only .heex matches are kept). With no paths, lib/**/*.heex is used and
matching nothing is reported as a note, not an error. An explicit path that does not exist, or a
glob that matches nothing, is an error. Symlinks are followed (Path.wildcard/1 and
File.read/1 do); files are deduplicated by absolute path and results are sorted.
Result
run/2 returns a map with :files (checked paths), :findings (sorted, deduplicated maps with
:check, :file, :line, :message), :errors (maps with :kind, :message and
optionally :file/:check; kinds :bad_path, :bad_option, :unknown_check, :read,
:check_failed) and :notes. A check that raises is reported as :check_failed, never as
"no findings".
Summary
Functions
Names of the available checks.
Runs the selected checks over the files matched by paths. See the moduledoc.
Types
@type finding() :: %{ check: String.t(), file: String.t(), line: pos_integer() | nil, message: String.t() }