Global pre-compile hook

I’d like to insert a certain module attribute into all modules.

Is there a way to modify the source code of each module before compilation?

Believe me, you do not want this…

What you really want is to use :elixirc_options if this is still related to your unused variables warning…

4 Likes

Thanks!

Turning off unused variables warning is a rational choice: it saves time.

I’d rather debug a simple “misspelled the variable name” issue once in a while than spend time underscoring vars, and then un-underscoring again when I need them :slight_smile:

No, you want to fix misspelled variables as they arise.

manager = foo()
# other stuff
maanger = bar(manager)
# other stuff
finalize(manager)

You really want to get a warning instantly that there is an unused variable isntead of a bunch of failing tests you can’t explain since you do not realize that there is a typo in the variable name.

If you really need common attributes or other boilerplate in your modules, create a boilerplate module which you use from any of your module. There is currently no way to globally inject anything. You have to opt in from anywhere explicitely.

If you really want to ignore that warning everywhere find an appropriate value for :elixirc_options or if it does not exist, convince the core team to introduce such an option.


But to be honest, in my opinion, if it really does not exist currently, I do only see two options, since I can set it locally per module, I either should be able to activate that flag globally as a compiler option, or not even locally per module. So either a compiler flag should be added or the module flag removed. I’d prefer the last one (doing lots of go recently where an unused variable is not only a warning but an error!)

3 Likes