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: find app_name when kw list is defined at the end #236

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

leandrocp
Copy link
Contributor

Close #235

So the logic here is to find where :app is defined inside project/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:

def project do
  default = [
    app: :igniter_test
  ]

  Keyword.merge(default, other())
end

But I'm not sure if that should even be supported. Let me know if there's a better approach.

@@ -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),
Copy link
Contributor Author

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)),
Copy link
Contributor

@zachdaniel zachdaniel Feb 21, 2025

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

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.

Igniter expects the definition body of Mix.Project#project to be exactly a keywordlist.
2 participants