<commit_before>defmodule Credo.Execution.Task.ValidateConfig do
  @moduledoc false

  use Credo.Execution.Task

  alias Credo.Check
  alias Credo.Check.Params
  alias Credo.CLI.Output.UI

  def call(exec, _opts) do
    exec
    |> validate_checks()
    |> remove_missing_checks()
    |> inspect_config_if_debug()<commit_msg>Warn on empty patterns for --only and --ignore<commit_after>defmodule Credo.Execution.Task.ValidateConfig do
  @moduledoc false

  use Credo.Execution.Task

  alias Credo.Check
  alias Credo.Check.Params
  alias Credo.CLI.Output.UI

  def call(exec, _opts) do
    exec
    |> validate_checks()
    |> validate_only_checks()
    |> validate_ignore_checks()
    |> remove_missing_checks()
    |> inspect_config_if_debug()
  end

  defp validate_only_checks(%Execution{only_checks: only_checks} = exec)
       when is_list(only_checks) do
    if Enum.any?(only_checks, &(&1 == "")) do
      UI.warn([
        :red,
        "** (config) Including all checks, since an empty string was given as a pattern: #{
          inspect(only_checks)
        }"
      ])
    end

    exec
  end

  defp validate_only_checks(exec) do
    exec
  end

  defp validate_ignore_checks(%Execution{ignore_checks: ignore_checks} = exec)
       when is_list(ignore_checks) do
    if Enum.any?(ignore_checks, &(&1 == "")) do
      UI.warn([
        :red,
        "** (config) Ignoring all checks, since an empty string was given as a pattern: #{
          inspect(ignore_checks)
        }"
      ])
    end

    exec
  end

  defp validate_ignore_checks(exec) do
    exec
{'fraction_non_alphanumeric': 0.10204081632653061, 'fraction_numerical': 0.0012755102040816326, 'mean_word_length': 2.9029850746268657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1550363', 'n_tokens_mistral': 550, 'n_tokens_neox': 502, 'n_words': 120}