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?
See example here: https://github.com/smorin/BootstrapEx
path = “lib/test_module.ex”
path = “some_path”
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
Thanks, formatting I don’t care about but want to support comments. Not having that sucks.
Checked out your thread and actually was looking to do the same thing. Maybe we can suggest adding comments to the AST.
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.