use indentsteps; use linewidth; fn towhee_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn towhee_counts(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value >= 0.0 && value <= 9007199254740991.0 && value % 1.0 == 0.0) { return false; } i += 1; } true } fn towhee_compute(indent: vector, widths: vector, step: f64, limit: f64) -> vector { if len(indent) != len(widths) { return []; } let mut i = 0; while i < len(indent) { if at(indent, i) > at(widths, i) { return []; } i += 1; } let levels = indentsteps_audit(indent, step); let lines = linewidth_audit(widths, limit); if len(levels) == 0 || len(lines) == 0 { return []; } let mut first = at(levels, 1); if first < 0.0 || (at(lines, 1) >= 0.0 && at(lines, 1) < first) { first = at(lines, 1); } let mut clean = 0; if first < 0.0 { clean = 1; } [clean, at(levels, 0), at(lines, 0), first] } // Combine indentation and line-width diagnostics for a measured source file. // Returns [clean, indentation violations, overlong rows, first problem row]. Supply aligned nonblank physical lines and their display widths. pub fn towhee_lint(indent: vector, widths: vector, step: f64, limit: f64) -> vector { if !towhee_counts(indent) { return []; } if !towhee_counts(widths) { return []; } if !(step >= 1.0 && step <= 9007199254740991.0 && step % 1.0 == 0.0) { return []; } if !(limit >= 1.0 && limit <= 9007199254740991.0 && limit % 1.0 == 0.0) { return []; } let result = towhee_compute(indent, widths, step, limit); if !towhee_finite(result) { return []; } result }