Add new line between blocks #72
Replies: 2 comments
-
hey ivan, sourceror doesn't do any rewriting for you. it just gives you the ability to handle manipulating AST with the comments inserted into metadata. you can use it to get the effect you're looking for, but you'll have to do that manipulation yourself =) |
Beta Was this translation helpful? Give feedback.
-
As novaugust mentions, you can do the manipulation yourself. code = """
import Foo.Bar
alias Foo.Bar
"""
ast = Sourceror.parse_string!(code)
You can see that the AST contains an modified =
Macro.postwalk(ast, fn
{:import, meta, args} ->
meta = put_in(meta, [:end_of_expression, :newlines], 2)
{:import, meta, args}
node ->
node
end)
modified
|> Sourceror.to_string()
|> IO.puts()
Of course you can adapt the code to match whatever you want to modify. However, keep in mind that:
|
Beta Was this translation helpful? Give feedback.
-
For example if we have
import Foo.Bar
alias Foo.Bar
I would like to add a new line so it looks like this
import Foo.Bar
alias Foo.bar
Beta Was this translation helpful? Give feedback.
All reactions