stil4m/elm-analyse

Feature: Apply all fixes at once

Opened this issue · 3 comments

Would be cool to apply all fixes at once. The solutions are pretty reliable and I’d be happy to trigger all changes with a single button in the web ui and/or a fix/f flag via command line.

@stil4m Is it straight forward to implement this feature or is a bulk change compilcated because of the current architecture?

If fixing starts at the bottom of the file and moves it way up, then it should definitely work (due to the code pointers that do not change).
The current architecture may be troubling due to that elm-analyse writes files back to disk after a fix and that actually invalidates 'old' messages which were created for a previous version of that file. I have to look into that a bit.

PS: I got a bit more time on my hands for the first time in three months thus there will hopefully be a bit more things happening on this project :)

How about starting with a naive approach: Applying the changes step by step, writing to disk and analyzing the file again. Would be quite inefficient, but is automating the same steps users are doing now manually.

antew commented

I have a branch up on https://github.com/antew/elm-analyse/tree/fixer-enhanced that implements this.

Fixing a single file

$ elm-analyse --fix src/Main.elm

Fixing a project

$ elm-analyse --fix-all

I may have been doing it wrong, but I tried the bottom up approach and I ran into issues when there were multiple fixes on one line, like in an import statement with a few unused variables mixed in.

I ended up having it fix-->reparse-->fix recursively until there are no more fixable issues, and only writing to disk at the end, doing it this way has the added benefit of fixing issues that only show up after another fix has been done.

I think an optimization on how I did it could be running the first fix for each line on each pass, it would greatly reduce the number of re-parsing passes it needs to make.