fmt: allow align threshold to be parametrized in calls to add_new_info (#21942)

This commit is contained in:
yuyi 2024-07-27 19:47:06 +08:00 committed by GitHub
parent 1b7b8123ca
commit 8af19ece2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,8 +5,6 @@ module fmt
import v.mathutil
const struct_field_align_threshold = 8
struct AlignInfo {
mut:
line_nr int
@ -18,6 +16,7 @@ mut:
struct AddInfoConfig {
pub:
use_threshold bool
threshold int = 8
}
fn (mut infos []AlignInfo) add_new_info(len int, type_len int, line int) {
@ -43,7 +42,7 @@ fn (mut infos []AlignInfo) add_info(len int, type_len int, line int, cfg AddInfo
len_diff := mathutil.abs(infos[i].max_len - len) +
mathutil.abs(infos[i].max_type_len - type_len)
if len_diff >= fmt.struct_field_align_threshold {
if len_diff >= cfg.threshold {
infos.add_new_info(len, type_len, line)
return
}