Auto-fix Engine Grooming #61
Replies: 3 comments 4 replies
-
ESLintI'd like to add some information about how ESLint's auto-fix engine behaves — they avoid dealing with conflict resolution by applying fixes in 10 passes. If two fixes conflict during a pass, then only one of them is applied, and after that, the rule is run again to generate a new fix that incorporates the applied fix already. If some fixes are still unapplied after 10 passes, it gives up (though I've never seen it happen in real life). We can use this approach ourselves too. And of course, we can still be smart about reordering fixes in such a way as to minimize conflicts. |
Beta Was this translation helpful? Give feedback.
-
The format of fixes and conflict resolutionThe Alternatively, we can have an internal merge algorithm such as ones used by Git, to merge two fixes to a file (if they can be merged cleanly) |
Beta Was this translation helpful? Give feedback.
-
Language serversThe most difficult fix to process might be |
Beta Was this translation helpful? Give feedback.
-
Here I quickly drafted my high-level vision of how the engine should behave. So, everything is criticizable and discussable, that is why the feature of creating discussions exists in the first place :) Feel free to complement and highlight/improve the bad parts.
Related issues: #20
Phase 1: Determine project specifics
There should be 2 ways to determine:
Things to determine:
Phase 2: Regroup diagnostics
Right now fixes are grouped by rule and that can cause conflicts when one rule moves the file and then another fix tries to change imports inside it but tries to access it by the old path.
A possible solution can be regrouping the diagnostics by a single file/folder and then applying them in batch keeping the link to the file/folder
Phase 3: Apply fixes
The solution should behave in a way that only fixes that can be fully done without errors happening in the FS. Because I think we need to avoid situations where some fix is applied partially and then throws an error, but some changes are already done in the FS. I think these situations will 100% irritate the hell out of the users.
Here we can manipulate some kind of virtual file system and then when we are sure that a needed fix (or a sequence of fixes, e.g. "move" -> "rename" -> "fix import statements inside") is possible to apply without errors, we commit it to the real FS.
Phase 4: Notify
Besides the errors that cannot be auto-fixed, we have to explicitly notify the user about what was auto-fixed and where. If for some reason, an auto-fix fails, notify about that too
Beta Was this translation helpful? Give feedback.
All reactions