Skip to content

Commit 71c5d56

Browse files
committed
chore: fix clippy warnings across crate
- Backtick `IndexMap`, `BTreeMap`, `IngredientList` in doc comments. - Replace `or_insert_with(Vec::new)` with `or_default()` in pantry index. - Use `contains_key` instead of `get(...).is_some()` in aisle tests. - Explicit `'_` lifetime on `Vec<Event<'_>>` in parser test helpers. - Normalize `PantryItem::WithAttributes` with no attributes back to `Simple` on parse so write→parse roundtrips preserve the variant.
1 parent 240cd74 commit 71c5d56

5 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/aisle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,9 @@ chili flakes
522522
let a = parse(input).unwrap();
523523
let p = a.ingredients_info();
524524
// All case variants should find the same ingredient
525-
assert!(p.get("chili flakes").is_some());
526-
assert!(p.get(&"Chili flakes".to_lowercase()).is_some());
527-
assert!(p.get(&"CHILI FLAKES".to_lowercase()).is_some());
525+
assert!(p.contains_key("chili flakes"));
526+
assert!(p.contains_key(&"Chili flakes".to_lowercase()));
527+
assert!(p.contains_key(&"CHILI FLAKES".to_lowercase()));
528528
assert_eq!(
529529
p.get("chili flakes").unwrap().common_name,
530530
p.get(&"Chili Flakes".to_lowercase()).unwrap().common_name

src/ingredient_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl IngredientList {
123123
///
124124
/// For each ingredient in the list, if it exists in the pantry with a valid quantity,
125125
/// subtract that quantity from the required amount. Only subtracts when units match.
126-
/// Returns a new IngredientList with the remaining quantities needed.
126+
/// Returns a new `IngredientList` with the remaining quantities needed.
127127
///
128128
/// # Arguments
129129
///

src/pantry.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ use crate::{
4242
/// format.
4343
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
4444
pub struct PantryConf {
45-
/// Map of sections to their items (IndexMap to preserve file order)
45+
/// Map of sections to their items (`IndexMap` to preserve file order)
4646
#[serde(flatten)]
4747
pub sections: IndexMap<String, Vec<PantryItem>>,
4848

4949
/// Index for fast ingredient lookups (lowercase name -> (section, index))
50-
/// Using BTreeMap for better cache locality and predictable iteration
50+
/// Using `BTreeMap` for better cache locality and predictable iteration
5151
#[serde(skip)]
5252
ingredient_index: BTreeMap<String, Vec<(String, usize)>>,
5353
}
@@ -187,7 +187,7 @@ impl PantryConf {
187187
let lowercase_name = item.name().to_lowercase();
188188
self.ingredient_index
189189
.entry(lowercase_name)
190-
.or_insert_with(Vec::new)
190+
.or_default()
191191
.push((section_name.clone(), idx));
192192
}
193193
}
@@ -510,6 +510,22 @@ fn parse_core(
510510
sections.insert("general".to_string(), general_items);
511511
}
512512

513+
// Normalize WithAttributes-with-no-attributes back to Simple, so
514+
// `write` → `parse` round-trips preserve the item variant.
515+
for items in sections.values_mut() {
516+
for item in items.iter_mut() {
517+
if let PantryItem::WithAttributes(attrs) = item {
518+
if attrs.bought.is_none()
519+
&& attrs.expire.is_none()
520+
&& attrs.quantity.is_none()
521+
&& attrs.low.is_none()
522+
{
523+
*item = PantryItem::Simple(attrs.name.clone());
524+
}
525+
}
526+
}
527+
}
528+
513529
// Build the index for fast lookups
514530
let mut ingredient_index = BTreeMap::new();
515531
for (section_name, items) in &sections {

src/parser/step.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ mod tests {
568568
use crate::{error::SourceReport, parser::token_stream::TokenStream};
569569
use test_case::test_case;
570570

571-
fn t(input: &str) -> (Vec<Event>, SourceReport) {
571+
fn t(input: &str) -> (Vec<Event<'_>>, SourceReport) {
572572
let mut tokens = TokenStream::new(input).collect::<Vec<_>>();
573573
// trim trailing newlines, block splitting should make sure this never
574574
// reaches the step function

src/parser/text_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mod tests {
3636
use indoc::indoc;
3737
use test_case::test_case;
3838

39-
fn t(input: &str) -> (Vec<Event>, SourceReport) {
39+
fn t(input: &str) -> (Vec<Event<'_>>, SourceReport) {
4040
let mut tokens = TokenStream::new(input).collect::<Vec<_>>();
4141
// trim trailing newlines, block splitting should make sure this never
4242
// reaches the step function

0 commit comments

Comments
 (0)