Skip to content

Commit af2b28d

Browse files
committed
Cleanup
1 parent 4a8a864 commit af2b28d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

ci/date-check/src/main.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ fn collect_dates_from_file(date_regex: &Regex, text: &str) -> Vec<(usize, Date)>
6161
},
6262
)
6363
}) {
64-
for chr in text[end_of_last_cap..byte_range.end].chars() {
65-
if chr == '\n' {
66-
line += 1;
67-
}
68-
}
64+
line += text[end_of_last_cap..byte_range.end]
65+
.chars()
66+
.filter(|c| *c == '\n')
67+
.count();
6968
dates.push((line, date));
7069
end_of_last_cap = byte_range.end;
7170
}
@@ -87,6 +86,7 @@ fn collect_dates(paths: impl Iterator<Item = PathBuf>) -> BTreeMap<PathBuf, Vec<
8786

8887
fn filter_dates(
8988
current_month: Date,
89+
min_months_since: u32,
9090
dates_by_file: impl Iterator<Item = (PathBuf, Vec<(usize, Date)>)>,
9191
) -> impl Iterator<Item = (PathBuf, Vec<(usize, Date)>)> {
9292
dates_by_file
@@ -99,7 +99,7 @@ fn filter_dates(
9999
current_month
100100
.months_since(*date)
101101
.expect("found date that is after current month")
102-
>= 6
102+
>= min_months_since
103103
})
104104
.collect::<Vec<_>>(),
105105
)
@@ -121,7 +121,7 @@ fn main() {
121121

122122
let dates_by_file = collect_dates(glob(&glob_pat).unwrap().map(Result::unwrap));
123123
let dates_by_file: BTreeMap<_, _> =
124-
filter_dates(current_month, dates_by_file.into_iter()).collect();
124+
filter_dates(current_month, 6, dates_by_file.into_iter()).collect();
125125

126126
if dates_by_file.is_empty() {
127127
println!("empty");
@@ -167,8 +167,14 @@ mod tests {
167167

168168
#[test]
169169
fn test_months_since() {
170-
let date1 = Date { year: 2020, month: 3 };
171-
let date2 = Date { year: 2021, month: 1 };
170+
let date1 = Date {
171+
year: 2020,
172+
month: 3,
173+
};
174+
let date2 = Date {
175+
year: 2021,
176+
month: 1,
177+
};
172178
assert_eq!(date2.months_since(date1), Some(10));
173179
}
174180

0 commit comments

Comments
 (0)