-
-
Notifications
You must be signed in to change notification settings - Fork 32
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: find app_name when kw list is defined at the end #236
base: main
Are you sure you want to change the base?
Conversation
@@ -26,8 +26,10 @@ defmodule Igniter.Project.Application do | |||
|> Sourceror.Zipper.zip() | |||
|
|||
with {:ok, zipper} <- Igniter.Code.Function.move_to_def(zipper, :project, 0), | |||
zipper <- Igniter.Code.Common.rightmost(zipper), | |||
true <- Igniter.Code.List.list?(zipper), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keyword.get_key/2
does check if it's a list already.
zipper <- Igniter.Code.Common.rightmost(zipper), | ||
true <- Igniter.Code.List.list?(zipper), | ||
{:ok, zipper} <- | ||
Igniter.Code.Common.move_to(zipper, &match?({:__block__, _, [:app]}, &1.node)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be too liberal. Any other keyword list that contains an app
option, anywhere in the structure could be construed as the app config we are looking for, no matter how deep we search. I think we should start simpler, going to the rightmost literal list, and otherwise complaining. We have a deps_location
pattern for allowing users to configure where in the deps function their list is, so we could eventually do similar patterns here, but this method can yield false positives which I think is more dangerous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was busy when I typed the above, sorry 😆 its not very clear.
The current feature could have a false positive, i.e if someone had something like this:
def project() do
[
foo: [app: :foo], # <- we'd find this one.
app: :foo
]
end
And false positives are dangerous. I think "left most list" is really the only safe heuristic to apply for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was clear enough 😄
Yeah that makes sense, I'm gonna look at that deps_location
and soon push changes to this branch.
Close #235
So the logic here is to find where
:app
is defined insideproject/0
, which does cover the case described at #235 and also cases where the kw list is assigned to a variable. Although it wouldn't cover some edge cases like for eg:But I'm not sure if that should even be supported. Let me know if there's a better approach.