View Source Credo.Execution (Credo v1.7.0)

Every run of Credo is configured via an Credo.Execution struct, which is created and manipulated via the Credo.Execution module.

Link to this section Summary

Functions

The Credo.Execution struct is created and manipulated via the Credo.Execution module.

Builds an Execution struct for the the given argv.

Returns the checks that should be run for a given exec struct.

Ensures that the given value is a %Credo.Execution{} struct, raises an error otherwise.

Returns the assign with the given name for the given exec struct (or return the given default value).

Returns the Credo.CLI.Command module for the given name.

Returns the name of the command, which should be run by the given execution.

Returns the value for the given switch_name.

Returns all issues for the given exec struct.

Returns all issues for the given exec struct that relate to the given filename.

Returns all issues grouped by filename for the given exec struct.

Returns the result with the given name for the given exec struct (or return the given default value).

Returns all source files for the given exec struct.

Returns all valid command names.

Halts further execution of the pipeline meaning all subsequent steps are skipped.

Halts further execution of the pipeline using the given halt_message.

Puts the given value with the given name as assign into the given exec struct and returns the struct.

Sets the issues for the given exec struct, overwriting any existing issues.

Puts a given pipeline in exec under pipeline_key.

Puts the given value with the given name as result into the given exec struct.

Runs the pipeline with the given pipeline_key and returns the result Credo.Execution struct.

Sets the exec values which strict implies (if applicable).

Returns the tags for a given check and its params.

Link to this section Functions

Link to this function

%Credo.Execution{}

View Source (struct)

The Credo.Execution struct is created and manipulated via the Credo.Execution module.

Builds an Execution struct for the the given argv.

Returns the checks that should be run for a given exec struct.

Takes all checks from the checks: field of the exec, matches those against any patterns to include or exclude certain checks given via the command line.

Link to this function

ensure_execution_struct(value, fun_name)

View Source

Ensures that the given value is a %Credo.Execution{} struct, raises an error otherwise.

Example:

exec
|> mod.init()
|> Credo.Execution.ensure_execution_struct("#{mod}.init/1")
Link to this function

get_assign(exec, name_or_list, default \\ nil)

View Source

Returns the assign with the given name for the given exec struct (or return the given default value).

Credo.Execution.get_assign(exec, "foo")
# => nil

Credo.Execution.get_assign(exec, "foo", 42)
# => 42

Returns the Credo.CLI.Command module for the given name.

Credo.Execution.get_command(exec, "explain")
# => Credo.CLI.Command.Explain.ExplainCommand

Returns the name of the command, which should be run by the given execution.

Credo.Execution.get_command_name(exec)
# => "suggest"
Link to this function

get_given_cli_switch(exec, switch_name)

View Source

Returns the value for the given switch_name.

Credo.Execution.get_given_cli_switch(exec, "foo")
# => "bar"

Returns all issues for the given exec struct.

Link to this function

get_issues(exec, filename)

View Source

Returns all issues for the given exec struct that relate to the given filename.

Link to this function

get_issues_grouped_by_filename(exec)

View Source

Returns all issues grouped by filename for the given exec struct.

Link to this function

get_plugin_param(exec, plugin_mod, param_name)

View Source

Returns the Credo.Plugin module's param value.

Credo.Execution.get_command(exec, CredoDemoPlugin, "foo")
# => nil

Credo.Execution.get_command(exec, CredoDemoPlugin, "foo", 42)
# => 42
Link to this function

get_result(exec, name, default \\ nil)

View Source

Returns the result with the given name for the given exec struct (or return the given default value).

Credo.Execution.get_result(exec, "foo")
# => nil

Credo.Execution.get_result(exec, "foo", 42)
# => 42

Returns all source files for the given exec struct.

Credo.Execution.get_source_files(exec)
# => [%SourceFile<lib/my_project.ex>,
#     %SourceFile<lib/credo/my_project/foo.ex>]
Link to this function

get_valid_command_names(exec)

View Source

Returns all valid command names.

Credo.Execution.get_valid_command_names(exec)
# => ["categories", "diff", "explain", "gen.check", "gen.config", "help", "info",
#     "list", "suggest", "version"]

Halts further execution of the pipeline meaning all subsequent steps are skipped.

The error callback is called for the current Task.

defmodule FooTask do
  use Credo.Execution.Task

  def call(exec) do
    Execution.halt(exec)
  end

  def error(exec) do
    IO.puts("Execution has been halted!")

    exec
  end
end
Link to this function

halt(exec, halt_message)

View Source

Halts further execution of the pipeline using the given halt_message.

The error callback is called for the current Task. If the callback is not implemented, Credo outputs the given halt_message.

defmodule FooTask do
  use Credo.Execution.Task

  def call(exec) do
    Execution.halt(exec, "Execution has been halted!")
  end
end
Link to this function

put_assign(exec, name_or_list, value)

View Source

Puts the given value with the given name as assign into the given exec struct and returns the struct.

Credo.Execution.put_assign(exec, "foo", 42)
# => %Credo.Execution{...}
Link to this function

put_issues(exec, issues)

View Source

Sets the issues for the given exec struct, overwriting any existing issues.

Link to this function

put_pipeline(exec, pipeline_key, pipeline)

View Source

Puts a given pipeline in exec under pipeline_key.

A pipeline is a keyword list of named groups. Each named group is a list of Credo.Execution.Task modules:

Execution.put_pipeline(exec, :my_pipeline_key,
  load_things: [ MyProject.LoadThings ],
  run_analysis: [ MyProject.Run ],
  print_results: [ MyProject.PrintResults ]
)

A named group can also be a list of two-element tuples, consisting of a Credo.Execution.Task module and a keyword list of options, which are passed to the Task module's call/2 function:

Execution.put_pipeline(exec, :my_pipeline_key,
  load_things: [ {MyProject.LoadThings, []} ],
  run_analysis: [ {MyProject.Run, [foo: "bar"]} ],
  print_results: [ {MyProject.PrintResults, []} ]
)
Link to this function

put_result(exec, name, value)

View Source

Puts the given value with the given name as result into the given exec struct.

Credo.Execution.put_result(exec, "foo", 42)
# => %Credo.Execution{...}
Link to this function

run_pipeline(initial_exec, pipeline_key)

View Source

Runs the pipeline with the given pipeline_key and returns the result Credo.Execution struct.

Execution.run_pipeline(exec, :my_pipeline_key)
# => %Credo.Execution{...}

Sets the exec values which strict implies (if applicable).

Link to this function

tags_for_check(check, params)

View Source

Returns the tags for a given check and its params.