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

Fix return type of Mix.Task.alias?/1 #6310

Merged
merged 4 commits into from
Jul 9, 2017

Conversation

npbee
Copy link
Contributor

@npbee npbee commented Jul 8, 2017

This function is currently returning either nil or the alias itself from the
mix file, so it doesn't match with the boolean return type indicated by the
documentation.

Thanks!

This function is currently returning either `nil` or the alias itself from the
mix file, so it doesn't match with the `boolean` return type indicated by the
documentation.
@@ -193,7 +193,10 @@ defmodule Mix.Task do
end

def alias?(task) when is_atom(task) do
Mix.Project.config[:aliases][task]
Copy link
Member

Choose a reason for hiding this comment

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

What about !!Mix.Project.config[:aliases][task]?

Can you also please change the tests to check for == true and == false accordingly?

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, can do!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed up some changes. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Maybe use != nil? It feels more descriptive to me. :bowtie:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm maybe, but wouldn't that be leaving the tests open to passing on truthy values?

Copy link
Member

Choose a reason for hiding this comment

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

@npbee x != nil only differs from !!x when x is false, because false != nil #=> true while !!false #=> false, but since [] here returns either a non-boolean term or nil, they are equivalent here. Since :aliases is a keyword list, can't we do Keyword.has_key?(Mix.Project.config()[:aliases], task)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, right thanks! I think I was confused thinking that we were referring to using != nil on the assertions.

I do like either != nil or Keyword.has_key? for being more descriptive. Is there an advantage to using Keyword.has_key?

Copy link
Member

Choose a reason for hiding this comment

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

Descriptiveness :) If we can, let's go with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok sounds good to me! Pushed up the change.

npbee added 2 commits July 8, 2017 08:59
Update the tests to assert explict `true` or `false` values instead of
truthy/falsy values.
@lexmag lexmag changed the title Fix return type of Mix.Task.alias? Fix return type of Mix.Task.alias?/1 Jul 8, 2017
@josevalim josevalim merged commit e526678 into elixir-lang:master Jul 9, 2017
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants