fix: find app_name when kw list is defined at the end#236
fix: find app_name when kw list is defined at the end#236leandrocp wants to merge 1 commit intoash-project:mainfrom
Conversation
|
|
||
| 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.
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.
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.
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
]
endAnd 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.
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
:appis 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.