From 82db8295bb98515bd3f4ec4569739d200fd12817 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Thu, 13 Aug 2026 11:16:51 +0700 Subject: [PATCH] style(parser): clear pre-existing clippy warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cargo clippy --all-targets -- -D warnings failed with 8 errors before the schema refactor and was never part of CI. Clearing them so the gate is meaningful from here on. All behaviour-preserving: slice contains() over iter().any(), is_multiple_of() over a modulo, a needless borrow in a test helper, and a doc-list indent. process_mapped_row keeps its 8 parameters behind an allow attribute — the signature mirrors the JS column map one-for-one, and bundling the indices into a struct would hide that correspondence. Kept separate from the schema change so that diff stays readable. --- 2016/tools/xlsxread/src/format_detect_2016.rs | 11 +++++++---- 2016/tools/xlsxread/src/transform.rs | 2 +- 2016/tools/xlsxread/tests/golden.rs | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/2016/tools/xlsxread/src/format_detect_2016.rs b/2016/tools/xlsxread/src/format_detect_2016.rs index 768a88c..8103a4e 100644 --- a/2016/tools/xlsxread/src/format_detect_2016.rs +++ b/2016/tools/xlsxread/src/format_detect_2016.rs @@ -7,7 +7,7 @@ /// /// 1. `separate-scores` — header row[0]=="SBD" && row[2]=="TOAN" /// Columns: SBD(0) HOTEN(1) TOAN(2) VAN(3) LY(4) HOA(5) SINH(6) SU(7) DIA(8) -/// NGOAINGUTN(9) NGOAINGUTL(10) NGOAINGU-total(11) +/// NGOAINGUTN(9) NGOAINGUTL(10) NGOAINGU-total(11) /// → maps col 11 → tieng_anh; no ngay_sinh / ten_cum_thi / gioi_tinh / DIEM_THI /// → JS: build-database.js:90–116 (processSeparateScoresRow) /// @@ -57,7 +57,7 @@ pub fn is_header_row_2016(row: &[Data]) -> bool { return false; } let first = row[0].to_string().trim().to_uppercase(); - KNOWN_HEADERS.iter().any(|h| *h == first.as_str()) + KNOWN_HEADERS.contains(&first.as_str()) } // --------------------------------------------------------------------------- @@ -217,6 +217,9 @@ pub fn process_separate_scores_row(row: &[Data], patterns: &CompiledPatterns) -> /// Mirrors `processMappedRow` at build-database.js:119–146. /// Gender is normalised: only "Nam" or "Nữ" are kept; everything else → None. /// (build-database.js:132: `(rawGioiTinh === "Nam" || rawGioiTinh === "Nữ") ? rawGioiTinh : null`) +// Mirrors the JS column map one-for-one; grouping the indices into a struct +// would obscure that correspondence for no benefit. +#[allow(clippy::too_many_arguments)] pub fn process_mapped_row( row: &[Data], sbd_idx: usize, @@ -237,8 +240,8 @@ pub fn process_mapped_row( // build-database.js:125–126: KNOWN_HEADERS.has(sbdUpper) || KNOWN_HEADERS.has(hoTenUpper) let sbd_upper = sbd.to_uppercase(); let ho_ten_upper = ho_ten.to_uppercase(); - if KNOWN_HEADERS.iter().any(|h| *h == sbd_upper.as_str()) - || KNOWN_HEADERS.iter().any(|h| *h == ho_ten_upper.as_str()) + if KNOWN_HEADERS.contains(&sbd_upper.as_str()) + || KNOWN_HEADERS.contains(&ho_ten_upper.as_str()) { return None; } diff --git a/2016/tools/xlsxread/src/transform.rs b/2016/tools/xlsxread/src/transform.rs index 1ea2d68..c228f41 100644 --- a/2016/tools/xlsxread/src/transform.rs +++ b/2016/tools/xlsxread/src/transform.rs @@ -326,7 +326,7 @@ mod tests { let s = "Toán: 8.5"; let scores = parse_scores(s, &p); assert_eq!(scores.get("toan"), Some(&8.5)); - assert!(scores.get("ngu_van").is_none()); + assert!(!scores.contains_key("ngu_van")); } #[test] diff --git a/2016/tools/xlsxread/tests/golden.rs b/2016/tools/xlsxread/tests/golden.rs index 47d1309..1e9d647 100644 --- a/2016/tools/xlsxread/tests/golden.rs +++ b/2016/tools/xlsxread/tests/golden.rs @@ -125,7 +125,7 @@ fn write_xlsx(path: &Path, sheets: &[(String, Vec)]) { ws.push_str(" \n"); } ws.push_str(" \n"); - zip.start_file(&format!("xl/worksheets/sheet{}.xml", i + 1), opts) + zip.start_file(format!("xl/worksheets/sheet{}.xml", i + 1), opts) .unwrap(); zip.write_all(ws.as_bytes()).unwrap(); } @@ -165,7 +165,7 @@ fn header_row() -> XlsxRow { fn data_row(idx: usize, scores: &str) -> XlsxRow { // Anonymised: name uses sequential pattern, SBD is purely synthetic - let name = if idx % 2 == 0 { + let name = if idx.is_multiple_of(2) { format!("Nguyen Van Test {:03}", idx) } else { format!("Tran Thi Test {:03}", idx)