JuliaFormatter.jl icon indicating copy to clipboard operation
JuliaFormatter.jl copied to clipboard

Option to add or at least not remove trailing semi-colons?

Open chriselrod opened this issue 2 years ago • 5 comments

When running code in the REPL, I prefer not to have it flooded with text. Especially every time a function returns a long vector.

Yet JuliaFormatter strips semicolons, meaning that is exactly what happens.

Note that code inside various blocks will often be run in the REPL whilst debugging.

chriselrod avatar Apr 07 '22 00:04 chriselrod

can you give an example ?

 julia> s = """
 a = 10;

 b = 20;
 """
 "a = 10;\n\nb = 20;\n"

 julia> format_text(s) |> print
 a = 10;

 b = 20;

the semicolons are preserved

domluna avatar Apr 07 '22 01:04 domluna

julia> format_text("""
       begin
           a = rand(100);
           sum(a)
       end
       """) |> println
begin
    a = rand(100)
    sum(a)
end

When debugging, I often run the contents of blocks in my REPL line by line.

chriselrod avatar Apr 07 '22 01:04 chriselrod

ok ic

CSTParser doesn't support semicolons really at all but I think we could do something similar to what we do for inline comments to catch these

domluna avatar Apr 07 '22 01:04 domluna

Could we also get have an option we can set in our .JuliaFormatter.toml to end all lines with a semicolon?

chriselrod avatar Apr 28 '22 19:04 chriselrod

The removal of trailing semicolons can actually break code. Minimal example:

julia> code = raw":($([]...);)"
":(\$([]...);)"

julia> code |> Meta.parse |> eval
quote
end

julia> format_text(code) |> Meta.parse |> eval
ERROR: syntax: "..." expression outside call

stev47 avatar Sep 28 '23 16:09 stev47