Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support options from task and config #170

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions lib/mix/tasks/sobelow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ defmodule Mix.Tasks.Sobelow do
{opts, _, _} = OptionParser.parse(argv, aliases: @aliases, switches: @switches)

root = Keyword.get(opts, :root, ".")
config = Keyword.get(opts, :config, false)
config = Keyword.get(opts, :config, true)
conf_file = root <> "/.sobelow-conf"
conf_file? = config && File.exists?(conf_file)

Expand All @@ -134,15 +134,16 @@ defmodule Mix.Tasks.Sobelow do

opts =
if conf_file? do
{:ok, opts} = File.read!(conf_file) |> Code.string_to_quoted()
opts
{:ok, file_opts} = File.read!(conf_file) |> Code.string_to_quoted()
# CLI args take precedence
Keyword.merge(file_opts, opts)
else
opts
end

{verbose, diff, details, private, strict, skip, mark_skip_all, clear_skip, router, exit_on,
format, ignored, ignored_files, all_details, out, threshold,
version} = get_opts(opts, root, conf_file?)
version} = get_opts(opts, root)

set_env(:verbose, verbose)

Expand Down Expand Up @@ -214,7 +215,7 @@ defmodule Mix.Tasks.Sobelow do
Application.put_env(:sobelow, key, value)
end

defp get_opts(opts, root, conf_file?) do
defp get_opts(opts, root) do
verbose = Keyword.get(opts, :verbose, false)
details = Keyword.get(opts, :details, nil)
all_details = Keyword.get(opts, :all_details)
Expand Down Expand Up @@ -249,22 +250,18 @@ defmodule Mix.Tasks.Sobelow do

format = out_format(out, format)

{ignored, ignored_files} =
if conf_file? do
{Keyword.get(opts, :ignore, []),
Keyword.get(opts, :ignore_files, []) |> Enum.map(&Path.expand(&1, root))}
else
ignored =
Keyword.get(opts, :ignore, "")
|> String.split(",")

ignored_files =
Keyword.get(opts, :ignore_files, "")
|> String.split(",")
|> Enum.reject(fn file -> file == "" end)
|> Enum.map(&Path.expand(&1, root))
ignored =
case Keyword.get(opts, :ignore, []) do
ignore_str when is_binary(ignore_str) -> String.split(ignore_str, ",")
ignore -> ignore
end

{ignored, ignored_files}
ignored_files =
case Keyword.get(opts, :ignore_files, []) do
ignore_files when is_list(ignore_files) ->
Enum.map(ignore_files, &Path.expand(&1, root))
ignore_files_str when is_binary(ignore_files_str) ->
for i <- String.split(ignore_files_str, ",", trim: true), do: Path.expand(i, root)
end

threshold =
Expand Down
2 changes: 1 addition & 1 deletion lib/sobelow/finding_log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ defmodule Sobelow.FindingLog do
[mod, _] = String.split(finding.type, ":", parts: 2)

%{
ruleId: Sobelow.get_mod(mod).id,
ruleId: Sobelow.get_mod(mod).id(),
message: %{
text: finding.type
},
Expand Down