I am looking for a way to read in a elixir module and replace functions with code you want to run. Anyone know of any examples of code on how to parse a module’s AST to match against a function and replace it?
TLDR: you can do this, but you can’t preserve code formatting, comments and other stuff which is not part of AST. I’ve been investigating a similar case here: Mix deps.add functionality
I don’t believe that’s good idea. Even if we would still not have formatting saved. I think that looking at formatter mix task may give more ideas, because it’s actually do not remove comments when changing file.