ForgeCredoChecks.TimingAndPrivateStateGuard (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

Timing sleeps and private process-state mutation hide the real contract.

Why

Process.sleep/1 makes tests depend on scheduler timing instead of a deterministic signal. :sys.replace_state/2 reaches into a process and mutates implementation details rather than exercising the public API.

Use behavioural contract coverage instead. The reference pattern for the Forge/Anubis migration lives in contracts/template_variables_contract_test.exs.

What is flagged

This check flags actual remote call nodes for Process.sleep/1 and :sys.replace_state/2. String literals, atom literals, and function captures that merely mention those names are not flagged.

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 moving callers to contract tests:

{ForgeCredoChecks.TimingAndPrivateStateGuard,
 excluded_paths: [~r"^test/legacy_timing/"]}

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.