Skip to content

Commit 4c06cdc

Browse files
authored
fix: resolve clippy warnings and formatting issues (#19)
- Replace manual range check with RangeInclusive::contains (links.rs) - Collapse nested if-let into single expression (writer.rs) - Remove unnecessary let binding before return (writer.rs) - Apply cargo fmt formatting
1 parent 3d1587c commit 4c06cdc

File tree

2 files changed

+55
-56
lines changed

2 files changed

+55
-56
lines changed

src/links.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn followed_by_file_extension(content: &[u8], end: usize) -> bool {
221221
j += 1;
222222
}
223223
// Valid extension: 1-6 alphanumeric chars, followed by non-alphanumeric or end
224-
ext_len >= 1 && ext_len <= 6
224+
(1..=6).contains(&ext_len)
225225
}
226226

227227
/// Check if the matched text looks like a bare date (YYYY-MM-DD).

src/writer.rs

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -261,70 +261,69 @@ fn parse_frontmatter_fields(
261261
}
262262

263263
// Try to parse as YAML via serde_yaml
264-
if let Ok(yaml) = serde_yaml::from_str::<serde_yaml::Value>(inner) {
265-
if let Some(map) = yaml.as_mapping() {
266-
for (k, v) in map {
267-
let key = match k.as_str() {
268-
Some(s) => s.to_string(),
269-
None => continue,
270-
};
271-
match key.as_str() {
272-
"tags" => {
273-
if let Some(seq) = v.as_sequence() {
274-
for item in seq {
275-
if let Some(s) = item.as_str() {
276-
tags.push(s.to_string());
277-
}
264+
if let Ok(yaml) = serde_yaml::from_str::<serde_yaml::Value>(inner)
265+
&& let Some(map) = yaml.as_mapping()
266+
{
267+
for (k, v) in map {
268+
let key = match k.as_str() {
269+
Some(s) => s.to_string(),
270+
None => continue,
271+
};
272+
match key.as_str() {
273+
"tags" => {
274+
if let Some(seq) = v.as_sequence() {
275+
for item in seq {
276+
if let Some(s) = item.as_str() {
277+
tags.push(s.to_string());
278278
}
279-
} else if let Some(s) = v.as_str() {
280-
// Handle inline `tags: foo` or `tags: [a, b]` parsed as string
281-
for t in s.split(',') {
282-
let t = t.trim();
283-
if !t.is_empty() {
284-
tags.push(t.to_string());
285-
}
279+
}
280+
} else if let Some(s) = v.as_str() {
281+
// Handle inline `tags: foo` or `tags: [a, b]` parsed as string
282+
for t in s.split(',') {
283+
let t = t.trim();
284+
if !t.is_empty() {
285+
tags.push(t.to_string());
286286
}
287287
}
288288
}
289-
"aliases" => {
290-
if let Some(seq) = v.as_sequence() {
291-
for item in seq {
292-
if let Some(s) = item.as_str() {
293-
aliases.push(s.to_string());
294-
}
289+
}
290+
"aliases" => {
291+
if let Some(seq) = v.as_sequence() {
292+
for item in seq {
293+
if let Some(s) = item.as_str() {
294+
aliases.push(s.to_string());
295295
}
296-
} else if let Some(s) = v.as_str() {
297-
for a in s.split(',') {
298-
let a = a.trim();
299-
if !a.is_empty() {
300-
aliases.push(a.to_string());
301-
}
296+
}
297+
} else if let Some(s) = v.as_str() {
298+
for a in s.split(',') {
299+
let a = a.trim();
300+
if !a.is_empty() {
301+
aliases.push(a.to_string());
302302
}
303303
}
304304
}
305-
_ => {
306-
// Serialize value back to a string representation
307-
let val_str = match v {
308-
serde_yaml::Value::String(s) => s.clone(),
309-
serde_yaml::Value::Number(n) => n.to_string(),
310-
serde_yaml::Value::Bool(b) => b.to_string(),
311-
serde_yaml::Value::Null => String::new(),
312-
other => {
313-
// serde_yaml may parse dates/timestamps as tagged
314-
// values. Serialize and clean up the output.
315-
let raw = serde_yaml::to_string(other)
316-
.unwrap_or_default()
317-
.trim_start_matches("---")
318-
.trim()
319-
.to_string();
320-
// Strip YAML sequence prefix artifacts (e.g., "- - 2026-03-31" → "2026-03-31")
321-
let cleaned = raw.trim_start_matches("- ").trim().to_string();
322-
cleaned
323-
}
324-
};
325-
if !val_str.is_empty() {
326-
scalars.insert(key, val_str);
305+
}
306+
_ => {
307+
// Serialize value back to a string representation
308+
let val_str = match v {
309+
serde_yaml::Value::String(s) => s.clone(),
310+
serde_yaml::Value::Number(n) => n.to_string(),
311+
serde_yaml::Value::Bool(b) => b.to_string(),
312+
serde_yaml::Value::Null => String::new(),
313+
other => {
314+
// serde_yaml may parse dates/timestamps as tagged
315+
// values. Serialize and clean up the output.
316+
let raw = serde_yaml::to_string(other)
317+
.unwrap_or_default()
318+
.trim_start_matches("---")
319+
.trim()
320+
.to_string();
321+
// Strip YAML sequence prefix artifacts (e.g., "- - 2026-03-31" → "2026-03-31")
322+
raw.trim_start_matches("- ").trim().to_string()
327323
}
324+
};
325+
if !val_str.is_empty() {
326+
scalars.insert(key, val_str);
328327
}
329328
}
330329
}

0 commit comments

Comments
 (0)