domluna / JuliaFormatter.jl

An opinionated code formatter for Julia. Plot twist - the opinion is your own.

Home Page:https://domluna.github.io/JuliaFormatter.jl/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

incorrect YAS indentation?

ericphanson opened this issue · comments

julia> using JuliaFormatter

julia> str = """
       @testset "hi" begin
           @testset "preserve existing row index" begin
               # we test this by first setting the numbers, then reversing the row
               # orders before grouping.
               plans_numbered = [rowmerge(plan; edf_signal_index)
                                 for (edf_signal_index, plan)
                                 in enumerate(signal_plans)]
           end
       end
       """;

julia> print(format_text(str; style=YASStyle()))
@testset "hi" begin
    @testset "preserve existing row index" begin
        # we test this by first setting the numbers, then reversing the row
        # orders before grouping.
        plans_numbered = [rowmerge(plan; edf_signal_index)
                          for (edf_signal_index, plan)
                              in
                              enumerate(signal_plans)]
    end
end

to me the original looks right; that the in should be aligned with the for and the [], since that's the level of comprehension.

would enumerate(...) be indented though?

do you mean like

@testset "hi" begin
    @testset "preserve existing row index" begin
        # we test this by first setting the numbers, then reversing the row
        # orders before grouping.
        plans_numbered = [rowmerge(plan; edf_signal_index)
                          for (edf_signal_index, plan) in
                              enumerate(signal_plans)]
    end
end

? Hm, yeah, I think that is better than

@testset "hi" begin
    @testset "preserve existing row index" begin
        # we test this by first setting the numbers, then reversing the row
        # orders before grouping.
        plans_numbered = [rowmerge(plan; edf_signal_index)
                          for (edf_signal_index, plan) in
                          enumerate(signal_plans)]
    end
end

so in aligns to the for then but the other stuff remains as is?

https://github.com/domluna/JuliaFormatter.jl/blob/master/test/yas_style.jl#L136-L178 these are good to look at. They don't test the positioning of in too much since the line it's placed on is dependent on the original source. In those examples it's on the same line as for

Yeah, I guess my take is for and in are "keywords" w/r/t/ for-loops and should be on equal footing, and other stuff can be on the same line as them or indented relative to them if they are on a new line.