Add new line between blocks #72
Unanswered
ivan-srsen
asked this question in
Q&A
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 =) |
0 replies
|
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:
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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
All reactions