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

Warn on unknown dependency options #1027

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions lib/hex/scm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ defmodule Hex.SCM do
repo = opts[:repo] || "hexpm"
path = cache_path(repo, name, lock.version)

unknown_options = Keyword.keys(opts) -- ~w[hex dest repo lock env build optional]a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if unknown_options != [] do
Hex.Shell.warn(
"#{name} dependency is using unknown options: " <>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very minor detail, but I'm wondering if this chosen phrasing has a (small) chance of being misunderstood?

As in, perhaps a phrase like "ex_doc dependency is using unknown options" could be understood to mean "a dependency of ex_doc is using unknown options", because the expression "ex_doc dependency" by itself could easily mean "a dependency of ex_doc".

To make the phrasing here more unambiguous, perhaps this could be worded "The dependency #{name} is using unknown options", which leaves no room for interpretation 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, updated!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and change it one more time so it's consistent with another similar message and right now we have:

ex_doc is missing its version requirement, use \">= 0.0.0\"
ex_doc is using unknown options: :dir, :typo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 👏 Looks great. Good call on refining the message further 🙂

Enum.map_join(unknown_options, ", ", &inspect/1)
)
end

case Hex.Parallel.await(:hex_fetcher, {:tarball, repo, name, lock.version}, @fetch_timeout) do
{:ok, :cached} ->
Hex.Shell.debug(" Using locally cached package (#{path})")
Expand Down
29 changes: 29 additions & 0 deletions test/hex/mix_task_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ defmodule Hex.MixTaskTest do
end
end

defmodule WithUnknownOptions do
def project do
[
app: :with_unknown_options,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ex_doc, dir: "/bad", typo: true}
]
]
end
end

defmodule WithNonMatchingRequirement do
def project do
[
Expand Down Expand Up @@ -882,6 +895,22 @@ defmodule Hex.MixTaskTest do
end)
end

test "deps.get with unknown options" do
Mix.Project.push(WithUnknownOptions)

in_tmp(fn ->
Hex.State.put(:cache_home, File.cwd!())

Mix.Task.run("deps.get")

assert_received {:mix_shell, :info,
["\e[33mex_doc is missing its version requirement, use \">= 0.0.0\"" <> _]}

assert_received {:mix_shell, :info,
["\e[33mex_doc dependency is using unknown options: :dir, :typo\e[0m"]}
end)
end

defp old_lock_tuple(lock_tuple) do
{elem(lock_tuple, 0), elem(lock_tuple, 1), elem(lock_tuple, 2), elem(lock_tuple, 3)}
end
Expand Down
Loading