Fix clippy warnings and make them all errors

This commit is contained in:
Dustin J. Mitchell 2020-12-24 17:39:49 +00:00
parent 161c38807d
commit 8989b0d2e3
12 changed files with 24 additions and 23 deletions

View file

@ -13,7 +13,7 @@ pub(crate) fn execute<W: WriteColor>(
_ => "(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(())
}

View file

@ -4,7 +4,7 @@ use termcolor::WriteColor;
pub(crate) fn execute<W: WriteColor>(w: &mut W, replica: &mut Replica) -> Fallible<()> {
replica.gc()?;
write!(w, "garbage collected.\n")?;
writeln!(w, "garbage collected.")?;
Ok(())
}

View file

@ -8,7 +8,7 @@ pub(crate) fn execute<W: WriteColor>(
server: &mut Box<dyn Server>,
) -> Fallible<()> {
replica.sync(server)?;
write!(w, "sync complete.\n")?;
writeln!(w, "sync complete.")?;
Ok(())
}

View file

@ -4,7 +4,7 @@ use termcolor::{ColorSpec, WriteColor};
pub(crate) fn execute<W: WriteColor>(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(())
}

View file

@ -18,10 +18,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
@ -32,7 +29,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.
@ -40,11 +37,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;
}
}
}

View file

@ -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

View file

@ -45,7 +45,7 @@ pub(super) fn apply_modification<W: WriteColor>(
task.remove_tag(&tag)?;
}
write!(w, "modified task {}\n", task.get_uuid())?;
writeln!(w, "modified task {}", task.get_uuid())?;
Ok(())
}

View file

@ -1,3 +1,4 @@
#![deny(clippy::all)]
/*!
This crate implements the command-line interface to TaskChampion.

View file

@ -38,13 +38,13 @@ 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)?;
}
if !summary {
write!(w, "\nSee `task help` for more detail\n")?;
writeln!(w, "\nSee `task help` for more detail")?;
}
Ok(())
}
@ -69,7 +69,7 @@ pub(crate) struct Subcommand {
impl Subcommand {
fn write_help<W: Write>(&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,

View file

@ -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};

View file

@ -1,3 +1,4 @@
#![deny(clippy::all)]
/*!
This crate implements the core of TaskChampion, the [replica](crate::Replica).

View file

@ -215,8 +215,8 @@ impl Task {
/// Iterate over the task's tags
pub fn get_tags(&self) -> impl Iterator<Item = Tag> + '_ {
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);