~cosmicrose/hex_licenses

a4b469780dde0cab6811fb78a23195eb60cfc5d6 — Rosa Richter 2 months ago f5594ed
Reduce complexity of lint function
1 files changed, 13 insertions(+), 9 deletions(-)

M lib/mix/tasks/licenses/lint.ex
M lib/mix/tasks/licenses/lint.ex => lib/mix/tasks/licenses/lint.ex +13 -9
@@ 29,15 29,7 @@ defmodule Mix.Tasks.Licenses.Lint do
  def run(args) do
    package = Mix.Project.get!().project()[:package]

    if is_nil(package) do
      Mix.shell().error("This project does not have :package key defined in mix.exs.")
      exit({:shutdown, 1})
    end

    if Enum.empty?(Keyword.get(package, :licenses, [])) do
      Mix.shell().error("This project's :package config has a nil or empty :licenses list.")
      exit({:shutdown, 1})
    end
    validate_package!(package)

    license_list =
      if "--update" in args do


@@ 92,6 84,18 @@ defmodule Mix.Tasks.Licenses.Lint do
    end
  end

  defp validate_package!(package) do
    if is_nil(package) do
      Mix.shell().error("This project does not have :package key defined in mix.exs.")
      exit({:shutdown, 1})
    end

    if Enum.empty?(Keyword.get(package, :licenses, [])) do
      Mix.shell().error("This project's :package config has a nil or empty :licenses list.")
      exit({:shutdown, 1})
    end
  end

  defp print_status({license, :not_approved}) do
    Mix.shell().info(" - \"#{license}\" is not OSI-approved.")
  end