From befe14e5f51ac0adee8059bc237dd51e72c342b5 Mon Sep 17 00:00:00 2001 From: Stefano Gessa Date: Fri, 15 Mar 2024 15:24:25 +0700 Subject: [PATCH] Fix credo --- lib/mix_audit/cli/audit.ex | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/mix_audit/cli/audit.ex b/lib/mix_audit/cli/audit.ex index b723380..4d76ff5 100644 --- a/lib/mix_audit/cli/audit.ex +++ b/lib/mix_audit/cli/audit.ex @@ -5,13 +5,11 @@ defmodule MixAudit.CLI.Audit do format = Keyword.get(opts, :format) ignored_advisory_ids = ignored_advisory_ids(opts) ignored_package_names = ignored_package_names(opts) - ignored_ids_from_file = ignored_ids_from_file(opts) # Synchronize and get security advisories advisories = MixAudit.Repo.advisories() |> Enum.reject(&(&1.id in ignored_advisory_ids)) - |> Enum.reject(&(&1.id in ignored_ids_from_file)) |> Enum.group_by(& &1.package) # Get project dependencies @@ -35,20 +33,20 @@ defmodule MixAudit.CLI.Audit do end defp ignored_advisory_ids(opts) do - opts - |> Keyword.get(:ignore_advisory_ids, "") - |> String.split(",") - |> Enum.map(&String.trim/1) + ignored_ids_from_cli = ignored_advisory_ids_from_cli(opts) + ignored_ids_from_file = ignored_advisory_ids_from_file(opts) + + Enum.uniq(ignored_ids_from_cli ++ ignored_ids_from_file) end - defp ignored_package_names(opts) do + defp ignored_advisory_ids_from_cli(opts) do opts - |> Keyword.get(:ignore_package_names, "") + |> Keyword.get(:ignore_advisory_ids, "") |> String.split(",") |> Enum.map(&String.trim/1) end - def ignored_ids_from_file(opts) do + def ignored_advisory_ids_from_file(opts) do case Keyword.get(opts, :ignore_file) do nil -> [] @@ -60,4 +58,11 @@ defmodule MixAudit.CLI.Audit do |> Enum.reject(fn line -> String.starts_with?(line, "#") || String.trim(line) == "" end) end end + + defp ignored_package_names(opts) do + opts + |> Keyword.get(:ignore_package_names, "") + |> String.split(",") + |> Enum.map(&String.trim/1) + end end