fredrikekre/Runic.jl

Ignore comments when formatting

Closed this issue · 3 comments

Currently, something like

A = [ # comment 
x 
]

gets transformed into

A = [
    # comment
    x,
]

Should # comment be ignored?

Something you can copy-paste more easily:

julia> str = raw"""
       A = [ # comment
       x
       ]
       """
"A = [ # comment\nx\n]\n"

julia> Runic.format_string(str)
"A = [\n    # comment\n    x,\n]\n"

julia> print(ans)
A = [
    # comment
    x,
]

This came up here JuliaGeometry/DelaunayTriangulation.jl#141 (comment)

This one is deliberate but perhaps it is (too) problematic? My thought was that if you have a comment in a list like this then the comment most likely apply to the following item, e.g.

A = [
    # First element is a
    a,
    # Second element is b
    b,
]

If you want a comment for the whole expression I would have put it before, e.g.

# This is array A
A = [
    a,
    b,
]

What do you think?

That's a good point. I can easily work around it, I only happened to notice since it broke after it was converted into markdown with Literate.jl. I think you are right that, in general, this transformation is a good idea. You can probably close this and I'll just make the edits to fix it in my PR

You probably know, but if you need Julia source comments in a Literate file you can use ##.