KristerV

KristerV

Package to remove unused aliases and imports

I got fed up with removing unused aliases manually so made a package for it: GitHub - KristerV/remove_unused_ex: Remove unused aliases and imports from Elixir code

Currently not yet released, because it seems strange to release a single function. What do you think, should I release it?

Notes

mix format plugin

initially started with making a plugin, but couldn’t figure out how to get the mix compile warnings in a fast way to the plugin. it seems that format plugins can in fact only run one function per file and running mix compile each time doesn’t make sense. and it wouldn’t be async anymore.

there is a workaround with aliases, so mix format would run the package just before the actual formatting. (see readme).

unexpected results

I never use the alias App.{One,Two,Three} format, so the package would remove the whole line even if only One is unused. If you guys deem this to be released I would figure out a solution for this.

Plus there’s probably other situations this fails. Haven’t really dug deep.

Should I release?

My worry is that releasing a single-function-package is just noise. And perhaps there’s a much better way of doing this in the first place? How do you currently remove unused aliases/imports?

The important file (only 47 lines) is here: lib/mix/tasks/remove_unused.ex if you want to check it out and comment.

Most Liked

sodapopcan

sodapopcan

That was my thinking. I had forgotten about recode as I haven’t tried it yet. A few months ago I was getting deep into syntax rewriting for a package I was working on, but then I got a new job (or rather a job, period) and haven’t been back to it yet.

Naw, I’ve just been feeling that my “hot take” to “attempted helpful solution” ratio has been off lately—it’s my own neurosis :sweat_smile: Really I default to not aliasing at all, except that there are non-insignificant number of situations where I do so it’s not a very useful thing to say in a forum reply. And of course it’s a personal taste kinda deal.

sodapopcan

sodapopcan

I feel for something like this to be bullet-proof you’d want to use Sourceror to figure out what is unsed aliases and remove them (this would work for those who use {}).

This will likely come off as a “nobody asked you” type of statement but my solution to this is to call alias close to where they are used, ie, the same logic that is applied to setting variables. If a group of functions use the same alias I put it above the first one and it acts like a “section divider”. If only one function uses an alias I call alias right in the function itself. I find it helps a lot with readability—if I jump to a function in a module I’m unfamiliar with, I don’t have to them jump to the top figure out if it has dependencies. I also never feel the annoyance of forgetting to delete aliases because it’s usually within view. I did, however, feel your pain when I worked on a codebase where everything had to be aliased and always be at the top.

I’m not trying to preach or anything. To each their own, of course!

Where Next?

Popular in RFCs Top

dergraf
Hey everyone! :wave: I’ve been working on a side project for the last 4 months that I’m excited to share—it’s called ProxyConf! ProxyCon...
New
gilest
Hi all Relatively new to Elixir, but was curious to see how Phoenix might run with a basic importmap configuration. Introducing, phoeni...
New
sleipnir
Hey! Want to contribute to a cool compiler project? Check out the good first issues in the Honey Potion Compiler! Honey Potion is a com...
New
simulacre7
Hi everyone, I’m building Aethrion, an early alpha Elixir runtime for persistent AI characters. Repo: GitHub - simulacre7/aethrion: A s...
New
ca1989
Hi all, this week I played a bit with Phoenix and Elm. I ended up with this POC: The repository contains a demo phoenix project (in ...
New
christhekeele
TL;DR: I’m planning on building a library, inspired by Vapor, to make configuring Elixir applications more straight-forward; in an approa...
New
Overbryd
Polyglot-Ex Rust and wasmex bindings for polyglot. State: Pre-release Hi there, I am starting a thread for my humble bindings library ...
New
bortzmeyer
Not a replacement for serious authoritative DNS servers, of course, but useful for some uses (such as returning the IP address of the DNS...
New
benlime
In the last couple of days I was playing around with LiveView, function components and animations. I ended up with a little prototype whi...
New
marick
TL;DR I’ve forked the Lens package, changed the API some, added new lens makers and – most importantly – added a ton of documentation. In...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29305 241
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52238 488
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New

We're in Beta

About us Mission Statement