I’ve installed Elixir with asdf and everything works fine so far except the linting. I’m not able to get a warning or problem linting with the VSCode ElixirLS plugin. I have a large Phoenix project which had warnings in the past but the warnings disappeared since I’m using asdf.
Here is a small example code from a dummy project:
defmodule BlaTest do
use ExUnit.Case
doctest Bla
test "greets the world" do
some_variable = 5
assert Bla.hello() == :world
end
end
When I run mix test I get a warning in the terminal: warning: variable “some_variable” is unused (if the variable is not meant to be used, prefix it with an underscore)
There’s a few considerations here. Elixir has to-be-compiled files (.ex) and script files (.exs). Warnings are only shown when one of those files are compiled by the compiler.
.ex files are only compiled if their individual contents had changed since the last time they were compiled. This means if you run mix compile twice in a row without changes to any file in between warnings will only show up on the first run and not on the second.
For .exs files compilation happens whenever script files are compiled by code using them. When you run mix test you’ll see warning for issues in test files, because the script files are compiled and executed by the test runner. Given tests files are .exs files and also not in a load elixirrc_path they’re not compiled when doing mix compile, so warning also won’t show up for the latter command.
Now to elixir-ls. Its integration can show you the warnings it sees when running (probably mix compile) and also only the ones reported the last time the command was run, as there’s no manifest keeping track of warnings and if they have been resolved. Compiling your whole project on each change would help somewhat, but is unlikely to be fast enough to be a viable option. It also still won’t catch all warnings as some script files in your project might not be compiled and also elixir-ls runs in a configured MIX_ENV, so all code not available to that MIX_ENV also won’t be compiled and therefore not be reported for.