dawnbeen / c_formatter_42

C language formatter for 42 norminette
GNU General Public License v3.0
176 stars 17 forks source link

not formatting correctly when line is too long #62

Closed lgrandco closed 1 year ago

lgrandco commented 1 year ago

when we continue the previous line on a new line, we need to indent twice instead of once, but it re formats to only one tab so we need to save without formatting. wrong (just formatted): image correct: image

younesaassila commented 1 year ago

Encountered the bug recently too and have just pushed a fix to my fork. Will soon open a PR here

cacharle commented 1 year ago

(please don't send code as screenshot 😢 , just the the triple back quote)

This is probably made by the line_breaker formatter of @keyhr.

younesaassila commented 1 year ago

This is caused by some weird Norminette exception that variable assignments have one additional indent when nesting occurs. Don't ask me the reasoning behind this.....

lgrandco commented 1 year ago

sorry for the screenshot, I just saw this issue https://github.com/dawnbeen/c_formatter_42/issues/50, so it seems that both assigning and calling a function add an indent level, that's why it needed one more here

lgrandco commented 1 year ago

so

        ft_fprintf(2, "\r%d/%d %ld %ld", i + 1, g->w.y, (t_u64)m,
            (t_u64)g->b.z);

and

            z = (t_v2d){g->b.rs + ((t_f64)j / g->w.x) * (g->b.re - g->b.rs),
                g->b.is + ((t_f64)i / g->w.y) * (g->b.ie - g->b.is)};

are now correctly formated, but

            z = ft_fprintf(2, "\r%d/%d %ld %ld", i + 1, g->w.y, (t_u64)m,
                (t_u64)g->b.z);;

should be

            z = ft_fprintf(2, "\r%d/%d %ld %ld", i + 1, g->w.y, (t_u64)m,
                    (t_u64)g->b.z);;
cacharle commented 1 year ago

@lgrandco can you clone the branch from #63 and test it on your local machine to make sure this is actually fixed?

lgrandco commented 1 year ago

it fixed

            z = ft_fprintf(2, "\r%d/%d %ld %ld", i + 1, g->w.y, (t_u64)m,
                    (t_u64)g->b.z);;

(correct)

but does not work for

            t_z.z = ft_fprintf(2, "\r%d/%d %ld %ld", i + 1, g->w.y, (t_u64)m,
                (t_u64)g->b.z);;

(same with)

t_z->z
younesaassila commented 1 year ago

Ah I see. The problem is it only matches {name} = ... but the regex doesn't match dot notation or arrow notation. No idea if there's even such a regex helper for that in the code already?

younesaassila commented 1 year ago

I mean perhaps I could change it to ... = ... (basically any line with an equal sign) but not sure if it's a good idea 🤔

younesaassila commented 1 year ago

Alright fixed now with a tweaked regex r"^\s*({decl})((\.|->){decl})*\s+=\s+[^;]*?;$"

lgrandco commented 1 year ago

everything seems good, thanks 👍