From 58117b901a043d9c27b7853873c6f1b7cc824d6e Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Fri, 22 Nov 2024 11:22:28 +0100 Subject: [PATCH] style: clean up code formatting and add notes --- src/helpers.rs | 1 + src/kinds.rs | 2 +- src/task.rs | 6 +++--- src/tasks.rs | 23 +++++++++++------------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index a640af4..98ded9d 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -36,6 +36,7 @@ impl ToTimestamp for DateTime { /// Parses the hour from a plain number in the String, /// with max of max_future hours into the future. +/// TODO parse HHMM as well pub fn parse_hour(str: &str, max_future: i64) -> Option> { str.parse::().ok().and_then(|hour| { let now = Local::now(); diff --git a/src/kinds.rs b/src/kinds.rs index 4a2ad74..736160d 100644 --- a/src/kinds.rs +++ b/src/kinds.rs @@ -1,7 +1,7 @@ use crate::task::MARKER_PARENT; use crate::tasks::HIGH_PRIO; use itertools::Itertools; -use nostr_sdk::{Alphabet, EventBuilder, EventId, Kind, Tag, TagKind, TagStandard}; +use nostr_sdk::{EventBuilder, EventId, Kind, Tag, TagKind, TagStandard}; use std::borrow::Cow; pub const TASK_KIND: Kind = Kind::GitIssue; diff --git a/src/task.rs b/src/task.rs index d53c138..22f506d 100644 --- a/src/task.rs +++ b/src/task.rs @@ -175,7 +175,7 @@ impl Task { } } - pub(crate) fn list_hashtags(&self) -> impl Iterator + use<'_> { + pub(crate) fn list_hashtags(&self) -> impl Iterator + '_ { self.tags().filter_map(|t| Hashtag::try_from(t).ok()) } @@ -362,13 +362,13 @@ mod tasks_test { assert_eq!(task.pure_state(), State::Done); task.props.insert( EventBuilder::new(State::Open.into(), "").tags([Tag::hashtag("tag2")]) - .custom_created_at(Timestamp::from(Timestamp::now() - 2)) + .custom_created_at(Timestamp::now() - 2) .sign_with_keys(&keys).unwrap()); assert_eq!(task.pure_state(), State::Done); assert_eq!(task.list_hashtags().count(), 2); task.props.insert( EventBuilder::new(State::Closed.into(), "") - .custom_created_at(Timestamp::from(Timestamp::now() + 1)) + .custom_created_at(Timestamp::now() + 1) .sign_with_keys(&keys).unwrap()); assert_eq!(task.pure_state(), State::Closed); } diff --git a/src/tasks.rs b/src/tasks.rs index 7c1f9a7..0ad733c 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -13,7 +13,7 @@ use crate::task::{State, Task, TaskState, MARKER_DEPENDS, MARKER_PARENT, MARKER_ use colored::Colorize; use itertools::Itertools; use log::{debug, error, info, trace, warn}; -use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, JsonUtil, Keys, Kind, Metadata, PublicKey, SingleLetterTag, Tag, TagKind, TagStandard, Timestamp, Url}; +use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, JsonUtil, Keys, Kind, Metadata, PublicKey, SingleLetterTag, Tag, TagKind, Timestamp, Url}; use regex::bytes::Regex; use tokio::sync::mpsc::Sender; @@ -403,7 +403,7 @@ impl TasksRelay { prompt.push_str(&format!(" -#{}", tag)); } prompt.push_str(&self.state.indicator()); - self.priority.map(|p| + self.priority.map(|p| prompt.push_str(&format!(" *{:02}", p))); prompt } @@ -505,7 +505,7 @@ impl TasksRelay { }) } - // TODO sparse is deprecated + // TODO sparse is deprecated and only left for tests pub(crate) fn filtered_tasks( &self, position: Option, @@ -977,7 +977,7 @@ impl TasksRelay { } self.submit( build_tracking(target) - .custom_created_at(Timestamp::from(now.as_u64() + offset)), + .custom_created_at(now + offset), ); } @@ -1025,7 +1025,7 @@ impl TasksRelay { }) } - fn context_hashtags(&self) -> impl Iterator + use<'_> { + fn context_hashtags(&self) -> impl Iterator + '_ { self.tags.iter().map(Tag::from) } @@ -1431,8 +1431,7 @@ impl Display for TasksRelay { for task in visible { writeln!( lock, - "{}", - self.properties.iter() + "{}", self.properties.iter() .map(|p| self.get_property(task, p.as_str())) .join(" \t") )?; @@ -1523,9 +1522,8 @@ pub(crate) fn join_tasks<'a>( }) } -fn referenced_events(event: &Event) -> impl Iterator + use < '_ > { -event.tags.iter() -.filter_map(| tag | match_event_tag(tag).map(| t | t.id)) +fn referenced_events(event: &Event) -> impl Iterator + '_ { + event.tags.iter().filter_map(|tag| match_event_tag(tag).map(|t| t.id)) } fn referenced_event(event: &Event) -> Option { @@ -1907,9 +1905,10 @@ mod tasks_test { EventBuilder::new(TASK_KIND, "sub") .tags([tasks.make_event_tag_from_id(parent, MARKER_PARENT)]) ); - assert_eq!(tasks.viewed_tasks().len(), 1); + assert_tasks_view!(tasks, [parent]); tasks.track_at(Timestamp::now(), Some(sub)); assert_eq!(tasks.get_own_events_history().count(), 1); + assert_tasks_view!(tasks, []); tasks.make_dependent_sibling("sibling"); assert_eq!(tasks.len(), 3); @@ -2065,7 +2064,7 @@ mod tasks_test { let mut tasks = stub_tasks(); let zero = EventId::all_zeros(); - tasks.track_at(Timestamp::from(Timestamp::now().as_u64() + 100), Some(zero)); + tasks.track_at(Timestamp::now() + 100, Some(zero)); assert_eq!( timestamps(tasks.get_own_events_history(), &[zero]) .collect_vec()