linter-elm-make icon indicating copy to clipboard operation
linter-elm-make copied to clipboard

Remove unused imports across project/current file

Open opsb opened this issue 8 years ago • 10 comments

As I'm just switching to Atom and haven't had the linter running in my editor previously I have a ton of unused imports. It would be fantastic if the following commands existed:

  1. Remove unused imports across project
  2. Remove unused imports in file

opsb avatar Jan 21 '17 10:01 opsb

How about also adding "Remove unused imports on save" option?

Cc: @mybuddymichael @splodingsocks

halohalospecial avatar Jan 22 '17 00:01 halohalospecial

@halohalospecial Makes sense to me! I am curious if you have any thoughts to when functionality like this should go into elmjutsu instead of linter-elm-make or vice versa?

mybuddymichael avatar Jan 22 '17 01:01 mybuddymichael

@mybuddymichael linter-elm-make features seem to be anything related to the output from elm-make (error highlighting, quick fixes), while elmjutsu features are those that uses information extracted from parsing (except for Install Package and Uninstall Package, which I'm thinking of removing or moving to another package).

halohalospecial avatar Jan 22 '17 02:01 halohalospecial

There are sometimes overlaps though. Like if we want to have a quick fix that also needs parsed info.

Just realized that Atom is the only editor/IDE where major Elm support features are spread across different packages/plugins :D

halohalospecial avatar Jan 22 '17 02:01 halohalospecial

How about also adding "Remove unused imports on save" option?

I'll try and take a look today

opsb avatar Jan 22 '17 09:01 opsb

The timing seems a little tricky regarding save/linting/removeImports. The linting happens after save(unless you have on the fly enabled) and because removeImports requires the linter to run first it means that it also can't be run until after save. This means that you have to hit save twice to save the results from removeImports. There doesn't appear to be anyway to force the linting to happen before save because even if I call it explicitly in the onWillSave hook https://github.com/mybuddymichael/linter-elm-make/blob/master/lib/linter-elm-make.js#L407 is async which means that it still runs after save. Potentially I can trigger a second save automatically but preventing an infinite loop is fiddly. Open to ideas if anyone has any.

opsb avatar Jan 22 '17 11:01 opsb

So I added a hack that does the job, https://github.com/mybuddymichael/linter-elm-make/pull/114/commits/33795c8c7623ba1fd4c60be5043399a455aa5739. It does work reliably but you definitely have to hold your nose.

opsb avatar Jan 22 '17 12:01 opsb

Ok, found a better approach, ~~https://github.com/mybuddymichael/linter-elm-make/pull/114/commits/32aa060d28725e97c486d6dca15fca406c9eb1a5#diff-b34cd59fb6c7fbe5ac5d92af133b9935R455~~ https://github.com/mybuddymichael/linter-elm-make/pull/114/files#diff-b34cd59fb6c7fbe5ac5d92af133b9935R135

opsb avatar Jan 22 '17 12:01 opsb

Should we also have "Add missing type annotations on save" and the "Add Missing Type Annotations" command?

halohalospecial avatar Jan 23 '17 05:01 halohalospecial

Should we also have "Add missing type annotations on save" and the "Add Missing Type Annotations" command?

happy to add these as well

opsb avatar Jan 23 '17 09:01 opsb