Meet SourceLevel, your automatic code reviewer

SourceLevel does continuous static analysis of your GitHub repositories and delivers it straight to your Pull Requests

Get started for free
Go to line 1
defmodule EngineCredo.Config do
Go to line 2
  @moduledoc """
Go to line 3
  Utility for loading Credo configuration, provided we have a root path. Then a
Go to line 4
  list of valid Elixir files is built for analysis.
Go to line 6
  Additional configuration is provided by the Code Climate engine config, which
Go to line 7
  is a JSON file (`/config.json`) residing at the container root by default.
Go to line 10
  @source_code_path Application.get_env(:engine_credo, :source_code_path)
Go to line 11
  @engine_config_file Application.get_env(:engine_credo, :engine_config_file)
Go to line 13
  defstruct source_code_path: nil,
Go to line 14
            execution: nil,
Go to line 15
            source_files: [],
Go to line 16
            invalid_files: []
Go to line 18
  def read, do: read(@source_code_path, @engine_config_file)
Go to line 20
  def read(source_code_path, engine_config_file) do
Go to line 21
    engine_config = read_engine_config(engine_config_file)
Go to line 23
    load(source_code_path, engine_config)
Go to line 26
  defp load(path, engine_config) do
Go to line 27
    execution = build_execution(path, engine_config)
Go to line 29
    {source_files, invalid_files} = find_source_files(execution)
Go to line 31
    execution =
Go to line 32
      execution
Go to line 33
      |> load_comment_configuration(source_files)

Use a function call when a pipeline is only one function long

Go to line 35
    %__MODULE__{
Go to line 36
      source_code_path: path,
Go to line 37
      source_files: source_files,
Go to line 38
      invalid_files: invalid_files,
Go to line 39
      execution: execution
Go to line 43
  defp read_engine_config(engine_config_file) do
Go to line 44
    engine_config_file
Go to line 45
    |> File.read!()
Go to line 46
    |> Poison.decode!()
Go to line 49
  defp build_execution(path, engine_config) do
Go to line 51
    |> read_config_file
Go to line 52
    |> reject_disabled_checks
Go to line 53
    |> create_struct
Go to line 54
    |> include_files_from(path, engine_config)
Go to line 55
    |> boostrap
Go to line 58
  defp read_config_file(path) do
Go to line 59
    exec = Credo.Execution.build()
Go to line 60
    Credo.Execution.Task.run(Credo.Execution.Task.AppendDefaultConfig, exec)
Go to line 62
    # true required for safe loading of `.credo.exs`.
Go to line 63
    {:ok, result} = Credo.ConfigFile.read_or_default(exec, path, nil, true)
Go to line 68
  defp reject_disabled_checks(engine_config) do
Go to line 70
      Enum.reject(engine_config.checks, fn
Go to line 71
        {_check, false} ->
Go to line 74
        {_check} ->
Go to line 77
        {_check, _opts} ->
Go to line 81
    %Credo.ConfigFile{engine_config | checks: checks}
Go to line 84
  defp create_struct(%Credo.ConfigFile{} = config_file) do
Go to line 85
    %Credo.Execution{
Go to line 86
      files: config_file.files,
Go to line 87
      checks: config_file.checks,
Go to line 88
      requires: config_file.requires,
Go to line 89
      strict: config_file.strict,
Go to line 90
      color: false
Go to line 94
  defp include_files_from(execution, path, engine_config) do
Go to line 95
    include_paths =
Go to line 96
      engine_config["include_paths"]
Go to line 97
      |> List.wrap()
Go to line 98
      |> Enum.map(&Path.join(path, &1))
Go to line 100
    update_in(execution.files[:included], fn files ->
Go to line 102
      |> Enum.concat(include_paths)
Go to line 103
      |> Enum.uniq()
Go to line 107
  # Filter out malformed Elixir files and also valid Elixir files with an unknown
Go to line 108
  # file extension (`.ex` or `.exs`).
Go to line 109
  defp find_source_files(execution) do
Go to line 111
    |> Credo.Sources.find()
Go to line 112
    |> Enum.filter(&String.ends_with?(&1.filename, [".ex", ".exs"]))
Go to line 113
    |> Enum.split_with(fn x -> x.status == :valid end)
Go to line 116
  defp load_comment_configuration(execution, source_files) do
Go to line 117
    comment_configuration =
Go to line 118
      source_files
Go to line 119
      |> Credo.Check.ConfigCommentFinder.run(execution, [])
Go to line 120
      |> Enum.into(%{})
Go to line 122
    %Credo.Execution{execution | config_comment_map: comment_configuration}
Go to line 125
  defp boostrap(execution) do
Go to line 127
    |> Credo.Execution.ExecutionIssues.start_server()
Go to line 128
    # TODO: Remove this once stop supporting the inline attribute configuration.
Go to line 129
    |> Credo.CLI.Output.UI.use_colors()