ForgeCredoChecks.TaintedSourceInspection (forge_credo_checks v0.8.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 high and works with any version of Elixir.

Explanation

Source-grep tests must be replaced with behavioural contract tests.

Why

Reading a non-test .ex / .exs file and then searching its text with =~, String.contains?, Regex.*, or Code.eval_string proves only that a spelling exists. It does not prove the code path works, and it breaks on behaviour-preserving refactors.

Use contract coverage instead: call the public producer/consumer API and assert the returned value or effect. For the Forge/Anubis migration, the reference pattern lives in contracts/template_variables_contract_test.exs.

What is flagged

This check flags source-grep constructs applied to values tainted from File.read! or File.stream! of a path literal that is not under test/ and ends in .ex or .exs. Taint is tracked through simple in-file bindings, module attributes, pipes, and common enumerable callbacks.

Terminal artifact reads are intentionally outside this check. Reading .md, .txt, .yml, .yaml, doc/, or docs/ artifacts remains quiet, even when the artifact text is searched.

Configuration

excluded_paths is a list of patterns (regexes or substrings) matched against each file's path; a matching file is skipped. Use it only as a shrinking migration bridge while replacing source-grep tests with contract tests:

{ForgeCredoChecks.TaintedSourceInspection,
 excluded_paths: [~r"^test/legacy_source_grep/"]}

Check-Specific Parameters

Use the following parameters to configure this check:

:excluded_paths

Paths skipped entirely (regexes or substrings).

This parameter defaults to [].

General Parameters

Like with all checks, general params can be applied.

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