-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add options for enabling/disabling Gradient type-checking for specific apps/files #124
Conversation
Awesome! I'm happy to merge this if we can get a test or two for the logic in place. Would you have the time to add them? |
Great - I can definitely add some tests for this. |
d83d549
to
158f605
Compare
Hi, just added some tests for this. They're a bit complicated; the existing testing looked like it only operated on individual files, but in my case I wanted to be able to edit the files in a project and then run the task on the entire project, which I ended up doing through the shell. I'm happy to walk through the changes if any of them are unclear. I'm thinking about maybe refactoring some of the logic from the Mix task for filtering files into something like The only other thing, which I'm now remembering, is that I wanted to add a note in the README for how to use this new logic. I'll add that in the next little bit. |
Thanks for the contribution! I approved the CI run and we get some formatting errors there, but it's not a biggie.
The result is that I get this:
This is quite easy to fix with the following patch - it's probably a regression from #121:
However, this results in:
With another patch:
We get:
But the printed paths don't seem to be valid - they're relative to the umbrella apps' dirs, not the umbrella top directory. Am I missing the point and the intended use is not to call |
Thanks for all the info - and no, you're not missing the point, it's definitely intended to be run that way. I'll look into these errors. Sorry about that, I guess I should've tested better! |
…ing/disabling Gradient checks Fix analyzing beam files instead of ex files Working on unit tests for changes Fix unit tests
1f9a007
to
bd04a48
Compare
Everything in this branch is now fixed -- should be good to go. I just saw #138. Looks like there are a lot more changes in that branch, which I haven't looked through all the way, but it looks like you've also contributed to that branch @erszcz. What do you want to do here? Still want this branch to be merged, or should I close this one and we merge #138 instead? |
@@ -133,7 +133,6 @@ defmodule Gradient do | |||
defp maybe_specify_forms(forms, opts) do | |||
unless opts[:no_specify] do | |||
forms | |||
|> put_source_path(opts) |
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.
As mentioned in #138 this line is not necessary because before maybe_specify_forms/2
is called, we already call put_source_path
.
@@ -0,0 +1,14 @@ | |||
defmodule Mix.Tasks.CleanExamples do |
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 had some test failures while running some of the tests that were fixed by removing the compiled test files so they could be re-compiled from scratch. I'm adding this mix task, along with an alias to call it before mix test
, to automate the process so that others won't experience the same issues.
@@ -66,14 +70,18 @@ defmodule Mix.Tasks.Gradient do | |||
|
|||
options = Enum.reduce(options, [], &prepare_option/2) | |||
|
|||
# Compile the project before the analysis | |||
maybe_compile_project(options) |
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 moved this earlier in the pipeline to avoid a specific issue - when you run mix clean
before mix gradient
inside examples/simple_umbrella_app
, you would get an error about AppA.hello()
being undefined.
When I dug in, the reason is that in Gradualizer, gradualizer_db:init/1
is called before AppA
is compiled, so Gradualizer doesn't have any of the sources from this project loaded.
It turns out that gradualizer_db:init/1
is called when we call Application.ensure_all_started(:gradualizer)
, so the solution is simply to move the compilation step above, so it happens before we start Gradualizer.
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.
Good catch, thanks!
File.cd!(dir) | ||
|
||
# mix clean first | ||
assert {_, 0} = System.cmd("mix", ["clean"]) |
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.
Added a mix clean
before any tests for simple_umbrella_app
, in order to reproduce the bug I mentioned.
…ror when reading file fails.
Hi @erszcz , any chance you could take a look at this check failure? https://github.com/esl/gradient/actions/runs/3440202375/jobs/5738398944
Looks like the error comes from this code: # lib/gradient.ex:194
defp maybe_prepend_app_path(app_path, path) do
unless is_absolute_path(path) do
String.to_charlist(app_path) ++ '/' ++ path # This is the line the error refers to
else
path
end
end Guessing this is related to josefs/Gradualizer#440 Edit: Sorry, I realize it's kind of a big ask to help debug code which I added ... but I'm pretty sure this code should be fine. Plus, I'm having a hard time digging into the Gradualizer source code to see what the real issue is here. If it could print a more specific error message, e.g. just including what types it thinks this expression currently resolves to (in addition to what it currently prints), that would be helpful. |
Thoughts on this one vs. #138 ? |
Hello @japhib If you could look into this PR #138 and ascertain if I followed your line of thought that would be great! |
Just left a comment on #138. I suspect that's the way to go. If you're fine with cherry-picking a few more changes (as mentioned in the other comment), I'll go ahead and close this branch. |
I also opened josefs/Gradualizer#484 since I feel the error message for the |
Superseded by #138. One more time, great work! |
My proposed solution for #123 . Let me know what you think of this approach.
Stuff left to do: