Credence.Pattern (credence v0.7.1)

Copy Markdown

Pattern phase — detects and fixes anti-patterns in Elixir code.

Delegates to the 117 rules implementing Credence.Pattern.Rule behaviour. Rules are discovered automatically and run in priority order (lower first), with module name as tiebreaker for determinism.

Summary

Functions

The short names of the rules that are on under opts. Derived from rule_status/1 so the two answers never disagree.

Like fix/2, but also returns a list of {rule_module, issue_count} tuples for every rule that actually fired and was applied.

Returns the status of every rule Credence found (or every rule in an explicit rules: list), as maps with

Functions

analyze(code_string, opts \\ [])

@spec analyze(
  String.t(),
  keyword()
) :: [Credence.Issue.t()]

enabled_rules(opts \\ [])

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

The short names of the rules that are on under opts. Derived from rule_status/1 so the two answers never disagree.

fix(code_string, opts \\ [])

@spec fix(
  String.t(),
  keyword()
) :: String.t()

fix_with_trace(code_string, opts \\ [])

@spec fix_with_trace(
  String.t(),
  keyword()
) :: {String.t(), [{module(), non_neg_integer() | :reverted}]}

Like fix/2, but also returns a list of {rule_module, issue_count} tuples for every rule that actually fired and was applied.

Every step is logged via Logger.debug with [credence_fix] prefix: rule name, issue count, whether the source changed, and a before/after diff of the lines that were modified.

Pattern rules operate on AST and assume semantically valid code. If the source does not compile, the pipeline is skipped entirely — applying AST transforms to code with undefined variables or functions risks introducing new errors and wasting an LLM retry attempt.

rule_status(opts \\ [])

@spec rule_status(keyword()) :: [
  %{
    rule: module(),
    name: String.t(),
    assumptions: [atom()],
    enabled: boolean(),
    missing: [atom()]
  }
]

Returns the status of every rule Credence found (or every rule in an explicit rules: list), as maps with:

  • :rule — the rule module
  • :name — its short name
  • :assumptions — the promises it needs
  • :enabled — whether all of them are on under opts right now
  • :missing — which needed promises are off

Honours the same assumptions: / config :credence settings as fix/2, so this is the place to answer "what did I promise, and why didn't this rule fire?"