JuliaFormatter.jl
JuliaFormatter.jl copied to clipboard
Default formatting removes semi colon, breaking code
I assign to a variable in the condition of a while loop in this (working) code:
getdata() = rand() < 0.5 ? rand() : missing
function dowork()
while !ismissing((val = getdata();))
println(val^2)
end
end
When I format the file with JuliaFormatter.format_file(), the semicolon is removed. The code then errors with “ERROR: MethodError: no method matching ismissing(; val::Float64)”, changing the behavior.
The versions are Julia 1.9.3, JuliaFormatter 1.0.36. I've tried it with the default and setting SciML style.
It has been pointed out that the code that breaks isn't the most readable. Originally posted here https://discourse.julialang.org/t/formatting-assignment-in-function-call/105269
I think this will be easier to do when we swap CSTParser for JuliaSyntax but atm placing the semicolon in the right spot can be problematic since it's only captured by the tokenizer and not the parse tree
This also comes up with array concatenation. I have the code
select!(data,
[[:programme_group_code,
:school_code,
:domicile,
:domicile_conversion,
:domicile_size,
:days_to_app,
:days_to_offer,
:registered]; columns])
that gets formatted to
select!(data,
[[:programme_group_code,
:school_code,
:domicile,
:domicile_conversion,
:domicile_size,
:days_to_app,
:days_to_offer,
:registered] columns])
(i.e., changing a vcat to an hcat.)