Pedantic clippy pass

This commit is contained in:
Joseph Ferano 2023-06-19 07:55:46 +07:00
parent 2f98c968f0
commit 26b1367820
5 changed files with 67 additions and 16 deletions

View File

@ -31,7 +31,7 @@ pub struct Task {
pub description: String,
}
/// The number of TaskEditFocus variants, used so we can "wrap around"
/// The number of `TaskEditFocus` variants, used so we can "wrap around"
/// with modulo when cycling through tasks with Tab/Backtab.
pub const EDIT_WINDOW_FOCUS_STATES: i8 = 4;
@ -133,6 +133,10 @@ impl<'a> State<'a> {
/// Selects the [`Column`] on the left. Does nothing if on the
/// first column.
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn select_column_left(&mut self) -> Result<(), Error> {
self.selected_column_idx = self.selected_column_idx.saturating_sub(1);
self.db_conn.set_selected_column(self.selected_column_idx)
@ -140,6 +144,10 @@ impl<'a> State<'a> {
/// Selects the [`Column`] on the right. Does nothing if on the
/// last column.
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn select_column_right(&mut self) -> Result<(), Error> {
self.selected_column_idx = min(self.selected_column_idx + 1, self.columns.len() - 1);
self.db_conn.set_selected_column(self.selected_column_idx)
@ -183,6 +191,10 @@ impl<'a> State<'a> {
/// Selects the [`Task`] above the current one. Does nothing if
/// it's the first task on the list
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn select_task_above(&mut self) -> Result<(), Error> {
let column = self.get_selected_column_mut();
column.selected_task_idx = column.selected_task_idx.saturating_sub(1);
@ -196,6 +208,10 @@ impl<'a> State<'a> {
/// Selects the [`Task`] below the current one. Does nothing if
/// it's the last task on the list
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn select_task_below(&mut self) -> Result<(), Error> {
let column = self.get_selected_column_mut();
column.selected_task_idx = min(
@ -212,6 +228,10 @@ impl<'a> State<'a> {
/// Selects the [`Task`] at the beginning of the list, no matter
/// where you are in the current [`Column`].
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn select_first_task(&mut self) -> Result<(), Error> {
let column = self.get_selected_column_mut();
column.selected_task_idx = 0;
@ -225,6 +245,10 @@ impl<'a> State<'a> {
/// Selects the [`Task`] at the end of the list, no matter
/// where you are in the current [`Column`].
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn select_last_task(&mut self) -> Result<(), Error> {
let column = self.get_selected_column_mut();
column.selected_task_idx = column.tasks.len().saturating_sub(1);
@ -251,12 +275,20 @@ impl<'a> State<'a> {
/// Moves the current [`Task`] up the list towards the top. Does
/// nothing if it's the first task.
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn move_task_up(&mut self) -> Result<(), Error> {
self.move_task(false)
}
/// Moves the current [`Task`] down the list towards the bottom. Does
/// nothing if it's the last task.
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn move_task_down(&mut self) -> Result<(), Error> {
self.move_task(true)
}
@ -294,12 +326,20 @@ impl<'a> State<'a> {
/// Moves the current [`Task`] to the [`Column`] on the left. Does
/// nothing if it's the first column.
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn move_task_column_left(&mut self) -> Result<(), Error> {
self.move_task_to_column(false)
}
/// Moves the current [`Task`] to the [`Column`] on the right. Does
/// nothing if it's the last column.
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn move_task_column_right(&mut self) -> Result<(), Error> {
self.move_task_to_column(true)
}
@ -339,6 +379,10 @@ impl<'a> State<'a> {
/// Inserts a new [`Task`] into [`Column::tasks`] at the bottom of
/// the list and saves the state to the DB.
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn add_new_task(&mut self, title: String, description: String) -> Result<(), Error> {
let col_id = self.get_selected_column().id;
let task = self.db_conn.create_new_task(title, description, col_id)?;
@ -355,6 +399,10 @@ impl<'a> State<'a> {
/// Edits the selected [`Task`] changing only it's title and/or
/// description. Does nothing if the [`Column`] is empty.
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn edit_task(&mut self, title: String, description: String) -> Result<(), Error> {
if let Some(selected_task) = self.get_selected_task_mut() {
selected_task.title = title;
@ -368,6 +416,10 @@ impl<'a> State<'a> {
/// Deletes the selected [`Task`] from the list. Does nothing if
/// the [`Column`] is empty.
///
/// # Errors
///
/// SQL related errors get bubbled up to here.
pub fn delete_task(&mut self) -> Result<(), Error> {
if let Some(task) = self.get_selected_task() {
let task_id = task.id;

View File

@ -57,7 +57,7 @@ impl DBConn {
Ok(tasks)
}
/// Uses [get_tasks_by_column][`DBConn::get_tasks_by_column`] over
/// Uses [`get_tasks_by_column`][`DBConn::get_tasks_by_column`] over
/// a loop to get all [`Column`] populated with the vec of.
/// [`Task`]
///
@ -155,8 +155,8 @@ impl DBConn {
Ok(())
}
/// This is a helper function in case we need to debug sort_order, because I ran into
/// a bug when I forgot to insert the sort_order when creating a task.
/// This is a helper function in case we need to debug `sort_order`, because I ran into
/// a bug when I forgot to insert the `sort_order` when creating a task.
#[allow(dead_code)]
fn get_sort_order(&self) -> Result<Vec<(i32, String, usize)>> {
let mut stmt = self.prepare(
@ -165,13 +165,13 @@ impl DBConn {
let mut tasks = Vec::new();
while let Some(row) = rows.next()? {
tasks.push((row.get(0)?, row.get(1)?, row.get(2)?,))
tasks.push((row.get(0)?, row.get(1)?, row.get(2)?,));
}
Ok(tasks)
}
/// The order of a [`Task`] in a [`Column`] needs to be saved to
/// the DB because SQLite doesn't have a way to handle the
/// the DB because `SQLite` doesn't have a way to handle the
/// ordering the internal [`Vec<Task>`] has. This takes the
/// current sorting order of two tasks and swaps them.
///

View File

@ -62,6 +62,7 @@ pub fn handle_task_edit(state: &mut State<'_>, key: event::KeyEvent) -> Result<(
Ok(())
}
#[allow(clippy::unit_arg)]
pub fn handle_main(state: &mut State<'_>, key: event::KeyEvent) -> Result<(), Error> {
match key.code {
KeyCode::Char('q') => Ok(state.quit = true),

View File

@ -3,7 +3,7 @@
//! kanban-tui is a TUI based application using [`ratatui`] for
//! rendering the UI and capturing user input interaction, with
//! [`Crossterm`] as the lower-level backend system for terminal
//! text-based interfaces. The data is saved to a SQLite database
//! text-based interfaces. The data is saved to a `SQLite` database
//! ideally placed in the root of your project. For this the
//! [`rusqlite`] crate provides the bindings to handle all the data
//! persistence.

View File

@ -189,6 +189,7 @@ fn draw_task_popup<B: Backend>(f: &mut Frame<'_, B>, state: &mut State<'_>, popu
}
}
#[allow(clippy::cast_possible_truncation, clippy::cast_precision_loss)]
fn draw_project_stats<B: Backend>(f: &mut Frame<'_, B>, area: Rect, state: &mut State<'_>) {
let block = Block::default()
.title("PROJECT STATS")
@ -199,17 +200,14 @@ fn draw_project_stats<B: Backend>(f: &mut Frame<'_, B>, area: Rect, state: &mut
let c3_len = state.columns[2].tasks.len();
let c4_len = state.columns[3].tasks.len();
let tocomplete_total = c1_len + c2_len + c3_len;
let percentage = (c3_len as f32 / tocomplete_total as f32 * 100.0) as u8;
let percentage = (c3_len as f32 / tocomplete_total as f32 * 100.0) as i8;
let list = List::new(vec![ListItem::new(vec![
Spans::from("Tasks per Column:"),
Spans::from(format!(" Todo ({})", c1_len)),
Spans::from(format!(" In Progress ({})", c2_len)),
Spans::from(format!(" Done ({})", c3_len)),
Spans::from(format!(" Ideas ({})", c4_len)),
Spans::from(format!(
"Progress: {} / {} - {}%",
c3_len, tocomplete_total, percentage
)),
Spans::from(format!(" Todo ({c1_len})")),
Spans::from(format!(" In Progress ({c2_len})")),
Spans::from(format!(" Done ({c3_len})")),
Spans::from(format!(" Ideas ({c4_len})")),
Spans::from(format!("Progress: {c3_len} / {tocomplete_total} - {percentage}%")),
])])
.block(block);