Composer.Lint.Format (composer v0.2.0)

Copy Markdown View Source

Renders Composer.Lint.Diagnostics for mix composer.cookbook.lint. Every function is pure: it returns text and prints nothing.

  • text/1 - the default: full messages, each after a path:line:col: location (relative to the current directory)
  • compact/2 - one line per diagnostic, file:line:col: severity: message [code], absolute paths, the message folded onto one line. The equivalent of Credo's flycheck and oneline formats, for editors.
  • json/1 - an array of Diagnostic.to_map/1
  • github/2 - GitHub Actions workflow commands (annotations)

compact/2 and github/2 never print a line without a location: a diagnostic that has none is printed at :1:1 of its first related file, or else of the fallback path.

Summary

Functions

One line per diagnostic: file:line:col: severity: message [code].

Folds a message onto one line: indented code blocks (lines indented by four spaces after a blank line) are dropped, and every run of whitespace becomes one space.

GitHub Actions workflow commands: ::error file=…,line=…,col=…,…::message. Paths are relative to the current directory, as GitHub matches them to the repository.

The diagnostics as a pretty JSON array.

The text format: %{errors: [...], warnings: [...]}, each a full message after its location.

Functions

compact(diagnostics, fallback \\ nil)

@spec compact([Composer.Lint.Diagnostic.t()], Path.t() | nil) :: String.t()

One line per diagnostic: file:line:col: severity: message [code].

fold(message)

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

Folds a message onto one line: indented code blocks (lines indented by four spaces after a blank line) are dropped, and every run of whitespace becomes one space.

github(diagnostics, fallback \\ nil)

@spec github([Composer.Lint.Diagnostic.t()], Path.t() | nil) :: String.t()

GitHub Actions workflow commands: ::error file=…,line=…,col=…,…::message. Paths are relative to the current directory, as GitHub matches them to the repository.

json(diagnostics)

@spec json([Composer.Lint.Diagnostic.t()]) :: String.t()

The diagnostics as a pretty JSON array.

text(diagnostics)

@spec text([Composer.Lint.Diagnostic.t()]) :: %{
  errors: [String.t()],
  warnings: [String.t()]
}

The text format: %{errors: [...], warnings: [...]}, each a full message after its location.