Hi,
Most of my compile warnings are things like unused variables which just need _ prepending to or unused functions, is there any tooling out there which will auto fix these on compile?
Hi,
Most of my compile warnings are things like unused variables which just need _ prepending to or unused functions, is there any tooling out there which will auto fix these on compile?
I don’t think there’s a consistent “auto fix” for these; a lot of the time I find I get unused variable errors when I make a copy-paste error:
foo = some_operation()
bar = some_other_operation(foo)
{some_complicated_function_call(foo, ...), some_complicated_function_call(foo, ...)}
That last foo
is supposed to be bar
, but the expression was copied over and the change didn’t happen.
Changing bar
to _bar
will silence the warning, but that’s like taking the batteries out of the fire alarm because it keeps going off.
This is a surprisingly common class of error - the PVS-Studio team has some great write-ups and results from scanning big open-source codebases.
Not currently, but I do think that a quickfix for prepending _
would be helpful (especially for function arguments). Of course as @al2o3cr you wouldn’t always want to use the quickfix, but it is nice to have it if it was there. If you want to tackle it, it would make a great contribution to https://github.com/elixir-lsp/elixir-ls/
After seeing this post I obviously started writing something to do this. After toiling for several undisclosed units of time I realized the next link in my search was fix_warnings – fix_warnings v0.1.3 where someone had already done it inarguable better than I had attempted. It handles variables and aliases, check it out!