Replaces AST pattern matches in Elixir source files.
Usage
mix ex_ast.replace 'pattern' 'replacement' [path ...]Options
--dry-run— show changes without writing files--inside 'pattern'— only replace inside ancestors matching this pattern--not-inside 'pattern'— skip replacements inside ancestors matching this pattern--parent 'pattern'/--not-parent 'pattern'— filter by direct semantic parent--ancestor 'pattern'/--not-ancestor 'pattern'— filter by semantic ancestor--has-child 'pattern'/--not-has-child 'pattern'— filter by direct semantic child--has-descendant 'pattern'/--not-has-descendant 'pattern'— filter by semantic descendant--has 'pattern'/--not-has 'pattern'— aliases for descendant filters
Examples
mix ex_ast.replace 'IO.inspect(expr, _)' 'expr' lib/
mix ex_ast.replace 'dbg(expr)' 'expr'
mix ex_ast.replace --dry-run '%Step{id: "subject"}' 'SharedSteps.subject_step(@opts)'
mix ex_ast.replace --not-inside 'test _ do _ end' 'IO.inspect(expr)' 'expr'
mix ex_ast.replace 'IO.inspect(expr)' 'Logger.debug(inspect(expr))' lib/ --parent 'def _ do ... end'
mix ex_ast.replace 'Repo.get!(schema, id)' 'Repo.fetch!(schema, id)' lib/ --has 'Repo.transaction(_)' --not-has 'IO.inspect(_)'