fmt: prevent possible trailing whitespace in wrapped infixes (#9573)
parent
646d46b4dc
commit
0eb59cf2bd
|
@ -1928,19 +1928,24 @@ pub fn (mut f Fmt) wrap_infix(start_pos int, start_len int, ignore_paren bool) {
|
||||||
for i, c in conditions {
|
for i, c in conditions {
|
||||||
cnd := c.trim_space()
|
cnd := c.trim_space()
|
||||||
if f.line_len + cnd.len < fmt.max_len[penalties[i]] {
|
if f.line_len + cnd.len < fmt.max_len[penalties[i]] {
|
||||||
if (i > 0 && i < conditions.len) || (ignore_paren && i == 0 && cnd[3] == `(`) {
|
if (i > 0 && i < conditions.len)
|
||||||
|
|| (ignore_paren && i == 0 && cnd.len > 5 && cnd[3] == `(`) {
|
||||||
f.write(' ')
|
f.write(' ')
|
||||||
}
|
}
|
||||||
f.write(cnd)
|
f.write(cnd)
|
||||||
} else {
|
} else {
|
||||||
|
is_paren_expr := (cnd[0] == `(` || (cnd.len > 5 && cnd[3] == `(`)) && cnd.ends_with(')')
|
||||||
|
final_len := ((f.indent + 1) * 4) + cnd.len
|
||||||
prev_len := f.line_len
|
prev_len := f.line_len
|
||||||
prev_pos := f.out.len
|
prev_pos := f.out.len
|
||||||
|
if i == 0 && !is_paren_expr {
|
||||||
|
f.remove_new_line({})
|
||||||
|
}
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
f.indent++
|
f.indent++
|
||||||
f.write(cnd)
|
f.write(cnd)
|
||||||
f.indent--
|
f.indent--
|
||||||
if f.line_len > fmt.max_len.last() && (cnd[0] == `(` || cnd[3] == `(`)
|
if final_len > fmt.max_len.last() && is_paren_expr {
|
||||||
&& cnd.ends_with(')') {
|
|
||||||
f.wrap_infix(prev_pos, prev_len, true)
|
f.wrap_infix(prev_pos, prev_len, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,3 +14,9 @@ fn unwrap_grouped_conds() {
|
||||||
fields = fields.filter((it.typ in [string_type, int_type, bool_type]
|
fields = fields.filter((it.typ in [string_type, int_type, bool_type]
|
||||||
|| c.table.types[int(it.typ)].kind == .struct_) && !it.attrs.contains('skip'))
|
|| c.table.types[int(it.typ)].kind == .struct_) && !it.attrs.contains('skip'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
clean_struct_v_type_name =
|
||||||
|
clean_struct_v_type_name.replace('_Array', '_array').replace('_T_', '<').replace('_', ', ') +
|
||||||
|
'>'
|
||||||
|
}
|
||||||
|
|
|
@ -9,3 +9,7 @@ fn unwrap_grouped_conds() {
|
||||||
_ := (also_inside_parens || just_as_above || but_this_is_also_more || than_a_single_line_could_fit) && end_cond
|
_ := (also_inside_parens || just_as_above || but_this_is_also_more || than_a_single_line_could_fit) && end_cond
|
||||||
fields = fields.filter((it.typ in [string_type, int_type, bool_type] || c.table.types[int(it.typ)].kind == .struct_) && !it.attrs.contains('skip'))
|
fields = fields.filter((it.typ in [string_type, int_type, bool_type] || c.table.types[int(it.typ)].kind == .struct_) && !it.attrs.contains('skip'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
clean_struct_v_type_name = clean_struct_v_type_name.replace('_Array', '_array').replace('_T_', '<').replace('_', ', ') + '>'
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
fn infix_in_multi_assign() {
|
||||||
|
child_width, child_height = child.adj_width + child.margin(.left) + child.margin(.right),
|
||||||
|
child.adj_height + child.margin(.top) + child.margin(.bottom)
|
||||||
|
}
|
Loading…
Reference in New Issue