Credence (credence v0.7.1)

Copy Markdown

Credence — Semantic Linter for Elixir.

Routes analysis and fixing through three phases:

  1. Syntax — string-level fixes for code that won't parse
  2. Semantic — fixes for compiler warnings (unused vars, undefined fns)
  3. Pattern — AST-level anti-pattern rules (the bulk of Credence)

Each phase has its own Rule behaviour and discovers rules automatically.

Summary

Functions

The short names of every rule that would run under opts, across all three rounds, in execution order. Derived from rule_status/1 so the two answers never disagree.

Reports which rules would run for the given opts, across all three rounds, without running them — the opts-only counterpart to fix/2.

Types

rule_status_entry()

@type rule_status_entry() :: %{
  round: :syntax | :semantic | :pattern,
  rule: module(),
  name: String.t(),
  assumptions: [atom()],
  enabled: boolean(),
  missing: [atom()]
}

Functions

analyze(code_string, opts \\ [])

@spec analyze(
  String.t(),
  keyword()
) :: %{valid: boolean(), issues: [Credence.Issue.t()]}

enabled_rules(opts \\ [])

@spec enabled_rules(keyword()) :: [String.t()]

The short names of every rule that would run under opts, across all three rounds, in execution order. Derived from rule_status/1 so the two answers never disagree.

fix(code_string, opts \\ [])

@spec fix(
  String.t(),
  keyword()
) :: %{
  code: String.t(),
  issues: [Credence.Issue.t()],
  applied_rules: [{module(), non_neg_integer() | :reverted}]
}

rule_status(opts \\ [])

@spec rule_status(keyword()) :: [rule_status_entry()]

Reports which rules would run for the given opts, across all three rounds, without running them — the opts-only counterpart to fix/2.

Returns one entry per rule, in execution order (Syntax → Semantic → Pattern), each a map with:

  • :round:syntax, :semantic, or :pattern
  • :rule — the rule module
  • :name — its short name
  • :assumptions — the promises it needs (always [] for Syntax/Semantic)
  • :enabled — whether it is eligible under opts
  • :missing — the needed promises that are off

Only the Pattern round is opts-filtered — by :assumptions and an explicit :rules list (see Credence.Pattern.rule_status/1). Syntax and Semantic rules are never opts-filtered, so every discovered rule comes back enabled: true. Whether a rule actually fires further depends on the code itself — Syntax only runs when the source won't parse, Semantic only on the compiler diagnostics it matches — which this opts-only view does not inspect.