6

When I do

mix compile

I get messages like

warning: variable "test_val" is unused
lib/myapp/mymodule.ex:46

I'm just hacking on a side project and I don't care about these warnings for now. Is there a way to turn this off?

Soviut
  • 88,194
  • 49
  • 192
  • 260
csch0
  • 523
  • 9
  • 21

2 Answers2

3

It doesn't look possible, but I could be wrong.

https://groups.google.com/forum/#!topic/elixir-lang-talk/XBnap4u6OkM

https://elixirforum.com/t/is-there-a-way-to-suppress-warnings-about-unused-variables/8637/7

The code that generates the warning (as best I can tell) is elixir_errors:warn and that doesn't have any flags to be able to turn off.

https://github.com/elixir-lang/elixir/search?p=1&q=%3Aelixir_errors.warn&type=&utf8=%E2%9C%93

Nor does it look like there are any code comments you can add to suppress the errors.

Consider it another facet of elixir's very opinionated viewpoint (right along with the "there's only one formatter, and it has no config")

AnilRedshift
  • 7,937
  • 7
  • 35
  • 59
  • 1
    Your point is valid, but as a side note, the formatter is actually configurable ;-) https://hexdocs.pm/mix/Mix.Tasks.Format.html#module-formatting-options – Patrick Oscity Mar 22 '18 at 12:58
  • And considering that he can shut off the "unused variable" warning with a relatively simple trick, I'd say your answer is somewhat inaccurate. – Onorio Catenacci Mar 23 '18 at 21:15
2

You can stop that particular compiler warning (i. e. test_val is unused) by proceeding the value with _. That is, rename the value to _test_val and you won't get the warning. But if you're warned the variable is unused, maybe you want to double check your code.

Onorio Catenacci
  • 14,928
  • 14
  • 81
  • 132