Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Feb 21, 2021
1 parent af37a62 commit f52731c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 27 deletions.
11 changes: 1 addition & 10 deletions lib/licensir/file_analyzer.ex
Expand Up @@ -23,16 +23,14 @@ defmodule Licensir.FileAnalyzer do
]

def analyze(dir_path) do
# IO.inspect(analyze_dir: dir_path)

Enum.find_value(@license_files, fn file_name ->
dir_path
|> Path.join(file_name)
|> File.read()
|> case do
{:ok, content} ->
# IO.inspect(analyze: file_name)
analyze_content(content)
#|> IO.inspect
{:error, _} -> nil
end
end)
Expand All @@ -41,7 +39,6 @@ defmodule Licensir.FileAnalyzer do
# Returns the first license that matches
defp analyze_content(content) do
content = clean(content)
# IO.inspect(content: content)

Enum.find_value(@files, fn {license, license_files} ->
found =
Expand All @@ -54,21 +51,15 @@ defmodule Licensir.FileAnalyzer do
|> File.read!()
|> clean()

# IO.inspect(license: license)
# IO.inspect(license_file: license_file)

# Returns true only if the content is a superset of the license text
content =~ license_text
end)

# IO.inspect(found: found)

if found, do: license, else: nil
end) || unrecognised(content)
end

defp unrecognised(_content) do
# IO.inspect(unrecognised_license: content)
:unrecognized_license_file
end

Expand Down
1 change: 0 additions & 1 deletion lib/licensir/guesser.ex
Expand Up @@ -24,7 +24,6 @@ defmodule Licensir.Guesser do
defp guess(hex, file) when length(hex) == 1 and hd(hex) == file, do: file

defp guess(hex, file) do
# IO.inspect(file: file)
Enum.join(hex, "; ") <> "; " <> file
end
end
20 changes: 7 additions & 13 deletions lib/licensir/scanner.ex
Expand Up @@ -6,15 +6,15 @@ defmodule Licensir.Scanner do

@human_names %{
agpl_v3: "AGPL v3",
apache2: "Apache 2",
apache2: "Apache 2.0",
bsd: "BSD",
cc0: "CC0-1.0",
gpl_v2: "GPLv2",
gpl_v3: "GPLv3",
cc0: "CC0 1.0",
gpl_v2: "GPL v2",
gpl_v3: "GPL v3",
isc: "ISC",
lgpl: "LGPL",
mit: "MIT",
mpl2: "MPL2",
mpl2: "MPL 2.0",
licensir_mock_license: "Licensir Mock License",
unrecognized_license_file: "Unrecognized license"
}
Expand All @@ -32,7 +32,6 @@ defmodule Licensir.Scanner do
|> filter_top_level(opts)
|> search_hex_metadata()
|> search_file()
# |> IO.inspect()
|> Guesser.guess()
end

Expand All @@ -53,7 +52,6 @@ defmodule Licensir.Scanner do
defp to_struct(deps) when is_list(deps), do: Enum.map(deps, &to_struct/1)

defp to_struct(%Mix.Dep{} = dep) do
# IO.inspect(dep)

%License{
app: dep.app,
Expand All @@ -66,7 +64,7 @@ defmodule Licensir.Scanner do

defp filter_top_level(deps, opts) do
if Keyword.get(opts, :top_level_only) do
Enum.filter(deps, & &1.dep.top_level)
Enum.filter(deps, &(&1.dep.top_level))
else
deps
end
Expand All @@ -92,7 +90,6 @@ defmodule Licensir.Scanner do

defp search_hex_metadata(%License{} = license) do
Map.put(license, :hex_metadata, search_hex_metadata(license.dep))
# IO.inspect(license)
end

defp search_hex_metadata(%Mix.Dep{} = dep) do
Expand Down Expand Up @@ -122,7 +119,6 @@ defmodule Licensir.Scanner do
end

defp search_file(%Mix.Dep{} = dep) do
# IO.inspect(search_file: dep)

license_atom =
Mix.Dep.in_dependency(dep, fn _ ->
Expand All @@ -132,8 +128,6 @@ defmodule Licensir.Scanner do
end
end)

# IO.inspect(license_atom: license_atom)

Map.get(@human_names, license_atom, to_string(license_atom))
Map.get(@human_names, license_atom)
end
end
4 changes: 2 additions & 2 deletions lib/mix/tasks/licenses.ex
Expand Up @@ -53,7 +53,7 @@ defmodule Mix.Tasks.Licenses do
_ =
Mix.Shell.IO.info([
:yellow,
"Notice: This is not a legal advice. Use the information below at your own risk."
"Notice: This is not a legal advice. Use the generated licensing information at your own risk."
])

rows
Expand All @@ -77,7 +77,7 @@ defmodule Mix.Tasks.Licenses do
IO.binwrite(file, "\n")
text
else
e ->
_e ->
_ =
Mix.Shell.IO.info([
:yellow,
Expand Down
1 change: 0 additions & 1 deletion lib/table_rex/renderer/text.ex
Expand Up @@ -77,7 +77,6 @@ defmodule TableRex.Renderer.Text do

rendered =
{table, meta, opts, []}
# |> render_top_frame
|> render_title
|> render_title_separator
|> render_header
Expand Down

0 comments on commit f52731c

Please sign in to comment.