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

Move explain to standalone task. #189

Merged
merged 3 commits into from
Jun 13, 2018
Merged

Move explain to standalone task. #189

merged 3 commits into from
Jun 13, 2018

Conversation

jeremyjh
Copy link
Owner

@jeremyjh jeremyjh commented Jun 13, 2018

resolves #173

@jeremyjh jeremyjh requested a review from asummers June 13, 2018 02:04
end

defp explanation_text(warning_name) do
warning = String.to_atom(warning_name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm always a bit weary of String.to_atom/1. Should be fine here, though, I think.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah its the best choice here, we can't leak.

defp explanation_text(warning_name) do
warning = String.to_atom(warning_name)
module = Map.get(Dialyxir.Warnings.warnings(), warning)
(module && module.explain()) || "Uknown warning named: #{warning_name}"
Copy link
Collaborator

@asummers asummers Jun 13, 2018

Choose a reason for hiding this comment

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

explain/1 will always return a truthy value, so this check is really

if module do
  module.explain()
else
  "Unknown warning named: #{warning_name}"
end

Also typo on Unknown

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or if you REALLY want to get fancy:

case Map.get(Dialyxir.Warnings.warnings(), warning) do
  nil -> 
    "Unknown warning named: #{warning_name}"
  module ->
    module.explain()
end

Copy link
Owner Author

Choose a reason for hiding this comment

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

If the warning name isn't found in the map, module will be nil so the left branch will fail and it prints the unknown. Do you just mean the if/case is more readable?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I think it's a little more honest as to intent. They're all functionally the same.

Copy link
Collaborator

@asummers asummers left a comment

Choose a reason for hiding this comment

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

After comments and tests pass 😄

@asummers
Copy link
Collaborator

Might be worth mentioning the new task in the README too

@jeremyjh jeremyjh merged commit bdab1da into master Jun 13, 2018
@jeremyjh jeremyjh deleted the jh-explain-task branch June 13, 2018 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mix dialyzer.explain task?
2 participants