Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Zheoni committed Jan 12, 2024
1 parent bdc5085 commit 49d5886
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
38 changes: 18 additions & 20 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub fn run(ctx: &Context, args: ListArgs) -> Result<()> {
let mut all = iter.collect::<Vec<_>>();
all.sort_unstable_by(|a, b| a.path().cmp(b.path()));
for entry in &all {
let row = list_row(ctx, &args, &entry)?;
let row = list_row(ctx, &args, entry)?;
table.add_row(row);
}
print!("{table}");
Expand All @@ -122,25 +122,23 @@ fn list_row(ctx: &Context, args: &ListArgs, entry: &CachedRecipeEntry) -> Result

let name = if args.absolute_paths {
entry.path().canonicalize()?.to_string_lossy().to_string()
} else if args.paths {
entry.path().to_string()
} else if let Some(parent) = entry
.path()
.strip_prefix(&ctx.base_path)
.unwrap()
.parent()
.filter(|p| !p.as_str().is_empty())
{
format!(
"{}{}{}",
parent.cyan().italic(),
std::path::MAIN_SEPARATOR.cyan(),
entry.name()
)
} else {
if args.paths {
entry.path().to_string()
} else if let Some(parent) = entry
.path()
.strip_prefix(&ctx.base_path)
.unwrap()
.parent()
.filter(|p| !p.as_str().is_empty())
{
format!(
"{}{}{}",
parent.cyan().italic(),
std::path::MAIN_SEPARATOR.cyan(),
entry.name()
)
} else {
entry.name().to_string()
}
entry.name().to_string()
};
row.add_ansi_cell(name);

Expand All @@ -159,7 +157,7 @@ fn list_row(ctx: &Context, args: &ListArgs, entry: &CachedRecipeEntry) -> Result
}

if args.check {
row.add_ansi_cell(format!(" [{}]", check_str(ctx, &entry)));
row.add_ansi_cell(format!(" [{}]", check_str(ctx, entry)));
} else {
row.add_cell("");
};
Expand Down
12 changes: 6 additions & 6 deletions src/serve/async_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Indexes {
}

fn insert_srch(&mut self, path: &Utf8Path) -> Result<(), cooklang_fs::Error> {
let meta = RecipeEntry::new(path.to_owned())
let meta = RecipeEntry::new(path)
.read()?
.metadata(&self.parser);
self.srch.insert(path.to_owned(), meta);
Expand Down Expand Up @@ -93,21 +93,21 @@ impl AsyncFsIndex {
match &update {
Update::Modified { path } => {
tracing::info!("Updated '{path}'");
let _ = indexes.write().await.revalidate(&path);
let _ = indexes.write().await.revalidate(path);
}
Update::Added { path } => {
tracing::info!("Added '{path}'");
let _ = indexes.write().await.insert(&path);
let _ = indexes.write().await.insert(path);
}
Update::Deleted { path } => {
tracing::info!("Deleted '{path}'");
indexes.write().await.remove(&path);
indexes.write().await.remove(path);
}
Update::Renamed { from, to } => {
tracing::info!("Renamed '{from}' to '{to}'");
let mut indexes = indexes.write().await;
indexes.remove(&from);
let _ = indexes.insert(&to);
indexes.remove(from);
let _ = indexes.insert(to);
}
}
// resend update after index is updated
Expand Down
2 changes: 1 addition & 1 deletion src/serve/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn recipe_entry_context(
image = Some(external_image.clone());
}

let name = meta_name(&m).unwrap_or(r.name()).to_string();
let name = meta_name(m).unwrap_or(r.name()).to_string();
metadata = context! {
tags => Value::from_iter(tags),
emoji => m.emoji,
Expand Down
2 changes: 1 addition & 1 deletion src/serve/handlers/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn search(
.search(
|entry, meta| match meta.and_then(|r| r.valid_output()) {
Some(m) => {
let name = meta_name(&m).unwrap_or(entry.name());
let name = meta_name(m).unwrap_or(entry.name());
srch.matches_recipe(name, &m.tags)
}
None => false,
Expand Down
4 changes: 2 additions & 2 deletions src/shopping_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ pub fn run(ctx: &Context, mut args: ShoppingListArgs) -> Result<()> {
let aisle = aisle_conf
.as_ref()
.map(|(content, path)| {
let res = cooklang::aisle::parse(&content);
let res = cooklang::aisle::parse(content);
if let Err(e) = res {
cooklang::error::write_rich_error(
&e,
path.as_str(),
&content,
content,
true,
anstream::stderr().lock(),
)?;
Expand Down

0 comments on commit 49d5886

Please sign in to comment.