diff --git a/cli/src/invocation/cmd/add.rs b/cli/src/invocation/cmd/add.rs index e3054992d..0b3618f4e 100644 --- a/cli/src/invocation/cmd/add.rs +++ b/cli/src/invocation/cmd/add.rs @@ -13,7 +13,7 @@ pub(crate) fn execute( _ => "(no description)".to_owned(), }; let t = replica.new_task(Status::Pending, description).unwrap(); - write!(w, "added task {}\n", t.get_uuid())?; + writeln!(w, "added task {}", t.get_uuid())?; Ok(()) } diff --git a/cli/src/invocation/cmd/gc.rs b/cli/src/invocation/cmd/gc.rs index 1aa9e2161..5fe20b74e 100644 --- a/cli/src/invocation/cmd/gc.rs +++ b/cli/src/invocation/cmd/gc.rs @@ -4,7 +4,7 @@ use termcolor::WriteColor; pub(crate) fn execute(w: &mut W, replica: &mut Replica) -> Fallible<()> { replica.gc()?; - write!(w, "garbage collected.\n")?; + writeln!(w, "garbage collected.")?; Ok(()) } diff --git a/cli/src/invocation/cmd/sync.rs b/cli/src/invocation/cmd/sync.rs index 6115b4822..9abc8b657 100644 --- a/cli/src/invocation/cmd/sync.rs +++ b/cli/src/invocation/cmd/sync.rs @@ -8,7 +8,7 @@ pub(crate) fn execute( server: &mut Box, ) -> Fallible<()> { replica.sync(server)?; - write!(w, "sync complete.\n")?; + writeln!(w, "sync complete.")?; Ok(()) } diff --git a/cli/src/invocation/cmd/version.rs b/cli/src/invocation/cmd/version.rs index 5c8c7577e..db3f2a80b 100644 --- a/cli/src/invocation/cmd/version.rs +++ b/cli/src/invocation/cmd/version.rs @@ -4,7 +4,7 @@ use termcolor::{ColorSpec, WriteColor}; pub(crate) fn execute(w: &mut W) -> Fallible<()> { write!(w, "TaskChampion ")?; w.set_color(ColorSpec::new().set_bold(true))?; - write!(w, "{}\n", env!("CARGO_PKG_VERSION"))?; + writeln!(w, "{}", env!("CARGO_PKG_VERSION"))?; w.reset()?; Ok(()) } diff --git a/cli/src/invocation/filter.rs b/cli/src/invocation/filter.rs index e6eacc9fc..4bca65825 100644 --- a/cli/src/invocation/filter.rs +++ b/cli/src/invocation/filter.rs @@ -36,10 +36,7 @@ pub(super) fn filtered_tasks( let mut res = vec![]; fn is_partial_uuid(taskid: &TaskId) -> bool { - match taskid { - TaskId::PartialUuid(_) => true, - _ => false, - } + matches!(taskid, TaskId::PartialUuid(_)) } // We will enumerate the universe of tasks for this filter, checking @@ -50,7 +47,7 @@ pub(super) fn filtered_tasks( Universe::IdList(ref ids) if ids.iter().any(is_partial_uuid) => { 'task: for (uuid, task) in replica.all_tasks()?.drain() { for id in ids { - if match id { + let in_universe = match id { TaskId::WorkingSetId(id) => { // NOTE: (#108) this results in many reads of the working set; it // may be better to cache this information here or in the Replica. @@ -58,11 +55,10 @@ pub(super) fn filtered_tasks( } TaskId::PartialUuid(prefix) => uuid.to_string().starts_with(prefix), TaskId::Uuid(id) => id == &uuid, - } { - if match_task(filter, &task) { - res.push(task); - continue 'task; - } + }; + if in_universe && match_task(filter, &task) { + res.push(task); + continue 'task; } } } diff --git a/cli/src/invocation/mod.rs b/cli/src/invocation/mod.rs index 760be3964..1920bb2dc 100644 --- a/cli/src/invocation/mod.rs +++ b/cli/src/invocation/mod.rs @@ -17,6 +17,7 @@ use filter::filtered_tasks; use modify::apply_modification; /// Invoke the given Command in the context of the given settings +#[allow(clippy::needless_return)] pub(crate) fn invoke(command: Command, settings: Config) -> Fallible<()> { log::debug!("command: {:?}", command); log::debug!("settings: {:?}", settings); @@ -88,7 +89,7 @@ pub(crate) fn invoke(command: Command, settings: Config) -> Fallible<()> { subcommand: Subcommand::Version, .. } => unreachable!(), - } + }; } // utilities for invoke diff --git a/cli/src/invocation/modify.rs b/cli/src/invocation/modify.rs index c3923f0ee..74b9b8d00 100644 --- a/cli/src/invocation/modify.rs +++ b/cli/src/invocation/modify.rs @@ -43,7 +43,7 @@ pub(super) fn apply_modification( task.remove_tag(&tag)?; } - write!(w, "modified task {}\n", task.get_uuid())?; + writeln!(w, "modified task {}", task.get_uuid())?; Ok(()) } diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 01900fbc6..379b3ea81 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(clippy::all)] /*! This crate implements the command-line interface to TaskChampion. diff --git a/cli/src/usage.rs b/cli/src/usage.rs index d91b449cc..b8251ffd1 100644 --- a/cli/src/usage.rs +++ b/cli/src/usage.rs @@ -40,8 +40,8 @@ impl Usage { "TaskChampion {}: Personal task-tracking\n\n", env!("CARGO_PKG_VERSION") )?; - write!(w, "USAGE:\n {} [args]\n\n", command_name)?; - write!(w, "TaskChampion subcommands:\n")?; + writeln!(w, "USAGE:\n {} [args]\n", command_name)?; + writeln!(w, "TaskChampion subcommands:")?; for subcommand in self.subcommands.iter() { subcommand.write_help(&mut w, summary)?; } @@ -58,7 +58,7 @@ impl Usage { modification.write_help(&mut w, summary)?; } if !summary { - write!(w, "\nSee `task help` for more detail\n")?; + writeln!(w, "\nSee `task help` for more detail")?; } Ok(()) } @@ -84,7 +84,7 @@ pub(crate) struct Subcommand { impl Subcommand { fn write_help(&self, mut w: W, summary: bool) -> Result<()> { if summary { - write!(w, " task {} - {}\n", self.name, self.summary)?; + writeln!(w, " task {} - {}", self.name, self.summary)?; } else { write!( w, diff --git a/sync-server/src/main.rs b/sync-server/src/main.rs index 6c5fde701..c69ac6e77 100644 --- a/sync-server/src/main.rs +++ b/sync-server/src/main.rs @@ -1,3 +1,5 @@ +#![deny(clippy::all)] + use crate::storage::{KVStorage, Storage}; use actix_web::{get, web, App, HttpServer, Responder, Scope}; use api::{api_scope, ServerState}; diff --git a/taskchampion/src/lib.rs b/taskchampion/src/lib.rs index 715dcaefa..fb91f36e7 100644 --- a/taskchampion/src/lib.rs +++ b/taskchampion/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(clippy::all)] /*! This crate implements the core of TaskChampion, the [replica](crate::Replica). diff --git a/taskchampion/src/task.rs b/taskchampion/src/task.rs index 2710a241c..8997919de 100644 --- a/taskchampion/src/task.rs +++ b/taskchampion/src/task.rs @@ -215,8 +215,8 @@ impl Task { /// Iterate over the task's tags pub fn get_tags(&self) -> impl Iterator + '_ { self.taskmap.iter().filter_map(|(k, _)| { - if k.starts_with("tag.") { - if let Ok(tag) = (&k[4..]).try_into() { + if let Some(tag) = k.strip_prefix("tag.") { + if let Ok(tag) = tag.try_into() { return Some(tag); } // note that invalid "tag.*" are ignored @@ -326,7 +326,7 @@ impl<'r> TaskMut<'r> { if let Some(v) = value { trace!("task {}: set property {}={:?}", self.task.uuid, property, v); - self.task.taskmap.insert(property.to_string(), v); + self.task.taskmap.insert(property, v); } else { trace!("task {}: remove property {}", self.task.uuid, property); self.task.taskmap.remove(&property);