gleam-lang / suggestions

📙 A place for ideas and feedback
26 stars 2 forks source link

Refactoring tool to automatically remove unused imports. #119

Open CrowdHailer opened 3 years ago

CrowdHailer commented 3 years ago

Gleam makes re-factoring much easier, which is a win. But when rapidly changing how things are structure a quite reasonable about of time is spent updating the imports, particuparly import gleam/option.{Some, None}

Returning an option or an error just seems to be one thing I change a lot. I have a lot of warnings like this

warning: Unused type
  ┌─ /opt/app/src/plum_mail/authentication.gleam:5:28
  │
5 │ import gleam/option.{None, Option, Some}
  │                            ^^^^^^

The type Option is never used, it can be safely removed.

Potentially a gleam clean or just part of gleam format would be nice to remove theese

lpil commented 3 years ago

I think this would be a useful refactoring tool for sure.

I think I would want it not in the formatter for a couple reasons. The first is that the formatter uses the untyped AST, so we would need to have a reverse-compiler process of some kind to go from typed to untyped code.

The second thing is that my experience of this in Go can be frustrating, especially if you don't have some automatic import insertion tool. Here's how it goes:

  1. You comment out some code
  2. The formatter removes the imports used by that code
  3. You uncomment the code
  4. Your module no longer compiles

But yes let's have this automation in future.