`if` statement formatting

Is there a way to improve formatting here?

const prev_valid = if (prev_pos < ctx.replacement_valid.len and
    ctx.replacement_valid[prev_pos])
    // then (awkward formatting)
    (ctx.replacements[prev_pos] != '\n')
else
    false;

I have had weird format enforcement cases before, but this one is really hitting the readability.

Pick your poison.

const prev_valid = if (prev_pos < ctx.replacement_valid.len and
    ctx.replacement_valid[prev_pos] //
)
    (ctx.replacements[prev_pos] != '\n')
else
    false;
const prev_valid = if (.{
    prev_pos < ctx.replacement_valid.len and
        ctx.replacement_valid[prev_pos],
}[0])
    (ctx.replacements[prev_pos] != '\n')
else
    false;
const prev_valid =
    prev_pos < ctx.replacement_valid.len and
    ctx.replacement_valid[prev_pos] and
    ctx.replacements[prev_pos] != '\n';
const prev_valid = prev_pos < ctx.replacement_valid.len and
    ctx.replacement_valid[prev_pos] and ctx.replacements[prev_pos] != '\n';

???

E: Castholm beat me to it.

semantically this is not the same tho

the second option is too heavy so not sure, but fmt will collapse the first one. number 3 is the winner! thanks!

zig fmt does not collapse the first one, note the comment.

Oh weird, I thought comments do not have weight during the formatting.

Why not like this?

const prev_valid =
    if (prev_pos < ctx.replacement_valid.len and ctx.replacement_valid[prev_pos])
        ctx.replacements[prev_pos] != '\n'
    else
        false;

it’s a parsing error for an invalid left hand of the assignment, I think its a regression though