KogenCredo.Diff.Finding (KogenCredo v0.1.0)

View Source

One rule hit, with text, JSON and GitHub workflow-command renderings.

Severity is :advisory (printed, never fails by default) or :error.

GitHub escaping follows the workflow-command rules: in the message %, \r and \n are escaped; in properties (file, title) : and , are escaped as well.

Summary

Functions

Makes text safe to print as one line: control characters (newlines, escapes, NUL) become \xNN, and surrounding whitespace is trimmed. CI log processors act on lines that start with ::, so repository-controlled text (paths, parser messages, git stderr) must not be able to start a line of its own.

Builds a finding anchored at the changed function.

One-line text form.

Builds an annotation line from raw parts, escaping each part.

GitHub annotation line (::warning file=...,line=...,title=...::message).

JSON object for one finding.

Map with string keys, ready for JSON.

Types

severity()

@type severity() :: :advisory | :error

t()

@type t() :: %KogenCredo.Diff.Finding{
  file: term(),
  function: term(),
  line: term(),
  message: term(),
  rule: term(),
  severity: term()
}

Functions

clean(text)

@spec clean(String.t()) :: String.t()

Makes text safe to print as one line: control characters (newlines, escapes, NUL) become \xNN, and surrounding whitespace is trimmed. CI log processors act on lines that start with ::, so repository-controlled text (paths, parser messages, git stderr) must not be able to start a line of its own.

for_change(rule, change, message)

@spec for_change(String.t(), KogenCredo.Diff.Change.t(), String.t()) :: t()

Builds a finding anchored at the changed function.

format(f)

@spec format(t()) :: String.t()

One-line text form.

github_line(level, file, line, title, message)

@spec github_line(
  String.t(),
  String.t() | nil,
  integer() | nil,
  String.t(),
  String.t()
) :: String.t()

Builds an annotation line from raw parts, escaping each part.

to_github(f)

@spec to_github(t()) :: String.t()

GitHub annotation line (::warning file=...,line=...,title=...::message).

to_json(f)

@spec to_json(t()) :: String.t()

JSON object for one finding.

to_map(f)

@spec to_map(t()) :: map()

Map with string keys, ready for JSON.