Skip to content

Do-block comment shifted to next line #1089

Description

@penelopeysm

Here, the #= comment =# gets shifted to the next line:

julia> s = """
       f() do x #= comment =#
           g
       end
       """
"f() do x #= comment =#\n    g\nend\n"

julia> ft(s) |> println
f() do x
    #= comment =#
    g
end

This is another case where the structure of the raw CST emitted by JuliaSyntax makes things a bit tricky to work with, and would be solved by a refactor akin to #1032. In particular, the comment is parsed as part of the block rather than part of the tuple. JuliaFormatter inserts a forced newline between the tuple and the block, which is usually completely sensible, just not here:

julia> fs(:cst, s)
     1:32     │[call]
     1:1      │  Identifier             ✔
     2:2      │  (
     3:3      │  )
     4:32     │  [do]
     4:4      │    Whitespace
     5:6do
     7:8      │    [tuple]
     7:7      │      Whitespace
     8:8      │      Identifier         ✔
     9:29     │    [block]
     9:9      │      Whitespace
    10:22     │      Comment
    23:27     │      NewlineWs
    28:28     │      Identifier         ✔
    29:29     │      NewlineWs
    30:32end

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Priority 2 — see contributing docsv3-cst-refactorThings that are best fixed through augmentation of JuliaSyntax's CST

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions