Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir: lint for confirming that every function has type sepcification

Tags:

lint

elixir

Is there a lint for Elixir (like for Javascript) which checks that every function has a type specification?

like image 637
tldr Avatar asked May 12 '14 03:05

tldr


1 Answers

There is an Erlang compiler switch, +warn_missing_spec, which does this, but I'm having trouble getting it to work with Elixir at the moment, I think there is a bug with it's parsing of the ELIXIR_ERL_OPTS environment variable which is converting +warn_missing_spec into -warn_missing_spec which isn't a valid compiler option. I'm going to open an issue on the tracker, but thought you might like to know that this does indeed exist.

EDIT: As José mentioned below, the correct flag is ERL_COMPILER_OPTIONS. You can enable the missing spec warning during compilation by doing the following:

ERL_COMPILER_OPTIONS="warn_missing_spec" mix compile

Keep in mind you may get superfluous warnings from Elixir itself, for functions like __MODULE__. It should still be useful though. One last thing to note, I discovered this morning that there is a problem using this flag with mix compile, and that it's currently only warning about mix.exs. This is being fixed, and may even be fixed by the time you see this, but it's something to be aware of.

like image 154
bitwalker Avatar answered Oct 27 '22 00:10

bitwalker