Credence.Semantic.Rule behaviour (credence v0.4.3)

Copy Markdown

Behaviour for semantic-level rules that fix compiler warnings.

Each rule matches specific compiler diagnostics and applies targeted fixes. Diagnostics come from Code.with_diagnostics/1 and have the shape:

%{message: String.t(), position: {line, col} | line, severity: :warning | :error}

Summary

Callbacks

Fix the source for the given diagnostic. Returns modified source.

Does this rule handle the given diagnostic?

Convert a matched diagnostic to a Credence issue.

Types

diagnostic()

@type diagnostic() :: %{
  message: String.t(),
  position: {integer(), integer()} | integer(),
  severity: :warning | :error
}

Callbacks

fix(source, diagnostic)

@callback fix(source :: String.t(), diagnostic()) :: String.t()

Fix the source for the given diagnostic. Returns modified source.

match?(diagnostic)

@callback match?(diagnostic()) :: boolean()

Does this rule handle the given diagnostic?

priority()

@callback priority() :: integer()

to_issue(diagnostic)

@callback to_issue(diagnostic()) :: Credence.Issue.t()

Convert a matched diagnostic to a Credence issue.