From 246d5e66880f7f788f57afb5c50f61a46421f649 Mon Sep 17 00:00:00 2001 From: Jana Lemke Date: Fri, 15 Apr 2022 16:37:40 +0200 Subject: [PATCH] Fix clippy lints --- notes.md | 7 ++++--- src/config.rs | 8 +------- src/courses.rs | 2 +- src/main.rs | 10 +++------- src/rofi.rs | 3 +-- src/util.rs | 2 +- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/notes.md b/notes.md index bd14137..599c971 100644 --- a/notes.md +++ b/notes.md @@ -1,5 +1,8 @@ # Things to do next - `check` complains about some of the defaults. Make sure default settings conform with opinions of `check` +- refactor to move functionality like rofi to shell scripts + Instead provide more scriptable functionality +- actual config instead of hardcoding values # Things to think about - Do I want to copy templates when creating a course? @@ -7,13 +10,11 @@ - sometimes I don't need them - annoying to do by hand - I don't know either way when creating the course -- Move `course.toml` to `.course.toml`? - - git doesn't automatically track hidden files I think (both pro and con) + # Things to do, if you are bored - Think about better parsing for Courses (semester) - Think about better error handling - - probably implement “bubbling up” of errors using the `?` operator - Think about better code separation/organization # Things learned diff --git a/src/config.rs b/src/config.rs index bffce13..5add9f4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,14 +9,8 @@ pub struct Config { pub note_extensions: Vec, } -#[derive(StructOpt)] +#[derive(StructOpt, Default)] pub struct ListOptions { #[structopt(short, long)] pub all: bool, } - -impl Default for ListOptions { - fn default() -> Self { - ListOptions { all: false } - } -} diff --git a/src/courses.rs b/src/courses.rs index f85e5cd..a17959a 100644 --- a/src/courses.rs +++ b/src/courses.rs @@ -72,7 +72,7 @@ impl Course { let mut coursestring = String::new(); handle = File::open(&path).unwrap(); handle.read_to_string(&mut coursestring).unwrap(); - let mut course: Course = toml::from_str(&coursestring).expect(&format!("{:?}", &path)); + let mut course: Course = toml::from_str(&coursestring)?; course.path = path.parent().unwrap().to_path_buf(); if options.all || course.is_current() { courses.push(course); diff --git a/src/main.rs b/src/main.rs index 14f953f..eb6d9dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,16 +116,12 @@ fn list_lectures(conf: &Config, options: ListOptions) -> Result> { let lectures = lectures? .into_iter() - .filter_map(|path| { + .filter(|path| { if let Some(ext) = path.extension() { let ext = ext.to_owned().to_string_lossy().into(); - if conf.note_extensions.contains(&ext) { - Some(path) - } else { - None - } + conf.note_extensions.contains(&ext) } else { - None + false } }) .collect(); diff --git a/src/rofi.rs b/src/rofi.rs index 2d060c2..e304e66 100644 --- a/src/rofi.rs +++ b/src/rofi.rs @@ -20,7 +20,7 @@ pub fn select_meeting(conf: &Config, options: &ListOptions) -> Result<()> { let meetings: Vec<_> = Course::list(conf, options)? .iter() .cloned() - .map(|c: Course| { + .flat_map(|c: Course| { if let Some(meetings) = c.meetings() { meetings.clone() } else { @@ -30,7 +30,6 @@ pub fn select_meeting(conf: &Config, options: &ListOptions) -> Result<()> { .map(move |m| (c.clone(), m.clone())) .collect::>() }) - .flatten() .collect(); let meeting_names: Vec<_> = meetings .iter() diff --git a/src/util.rs b/src/util.rs index 4b39424..927b565 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; use std::time::SystemTime; pub fn to_snail_case(from: impl Into) -> String { - from.into().replace(" ", "_").to_lowercase() + from.into().replace(' ', "_").to_lowercase() } // pub fn to_title_case(from: &str) -> String {