From b7cd729e261cdd5cf0f22c073b573682d86a51f8 Mon Sep 17 00:00:00 2001 From: Attila Repka Date: Tue, 24 Sep 2024 18:32:06 +0200 Subject: [PATCH] feat(ft): clippy --- .github/workflows/tests.yml | 8 ++++++++ src/app.rs | 2 +- src/cli.rs | 4 ++-- src/db.rs | 2 +- src/model.rs | 14 +++++++------- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d347ed6..b5b03a3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,15 @@ jobs: steps: - uses: actions/checkout@v3 + + - name: lint + run: cargo fmt -- --check + + - name: clippy + run: cargo clippy -- -D warnings + - name: build run: cargo build --verbose + - name: run tests run: cargo test --verbose diff --git a/src/app.rs b/src/app.rs index 437db64..bbe625a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -38,7 +38,7 @@ impl App { let mut terminal = Self::init_terminal()?; while !self.exit { - terminal.draw(|frame| self.ui.run(frame, &mut self.model))?; + terminal.draw(|frame| self.ui.run(frame, &self.model))?; self.handle_events().await?; } diff --git a/src/cli.rs b/src/cli.rs index fd533fc..12e76e7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,9 +4,9 @@ use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about = "sqliters", long_about = None)] pub struct Args { - /// Input archive file + /// Input sqlite file #[clap(long, short)] - pub input_file: String, + pub input: String, } impl Args { diff --git a/src/db.rs b/src/db.rs index 836785a..5a6eeee 100644 --- a/src/db.rs +++ b/src/db.rs @@ -141,7 +141,7 @@ impl Sqlite { .into_iter() .map(|row| { row.columns() - .into_iter() + .iter() .map(|column| { let ordinal = column.ordinal(); let type_name = column.type_info().name(); diff --git a/src/model.rs b/src/model.rs index 66329f7..7739ff7 100644 --- a/src/model.rs +++ b/src/model.rs @@ -61,7 +61,7 @@ impl Table { &self.rows } pub fn schema(&self) -> &str { - &self.schema.as_str() + self.schema.as_str() } } @@ -130,7 +130,7 @@ impl Model { let i = match self.state.selected() { Some(i) => match self.view_state { ViewState::Main => { - if i >= self.tables.len().checked_sub(1).unwrap_or(0) { + if i >= self.tables.len().saturating_sub(1) { 0 } else { i + 1 @@ -138,7 +138,7 @@ impl Model { } ViewState::Table => match self.tables.get(self.selected_table_id) { Some(table) => { - if i >= table.rows().len().checked_sub(1).unwrap_or(0) { + if i >= table.rows().len().saturating_sub(1) { 0 } else { i + 1 @@ -158,7 +158,7 @@ impl Model { Some(i) => match self.view_state { ViewState::Main => { if i == 0 { - self.tables.len().checked_sub(1).unwrap_or(0) + self.tables.len().saturating_sub(1) } else { i - 1 } @@ -166,7 +166,7 @@ impl Model { ViewState::Table => match self.tables.get(self.selected_table_id) { Some(table) => { if i == 0 { - table.rows().len().checked_sub(1).unwrap_or(0) + table.rows().len().saturating_sub(1) } else { i - 1 } @@ -214,7 +214,7 @@ impl Model { .state .selected() .unwrap_or(0) - .min(self.tables.len().checked_sub(1).unwrap_or(0)); + .min(self.tables.len().saturating_sub(1)); self.state = TableState::default().with_selected(0); self.view_state = ViewState::Main; for i in 0..self.tables.len() { @@ -223,7 +223,7 @@ impl Model { self.tables[i].columns = Self::columns(None, &self.db, &ViewState::Main).await?; } self.scroll_state = - ScrollbarState::new((self.tables.len().checked_sub(1).unwrap_or(0)) * ITEM_HEIGHT); + ScrollbarState::new(self.tables.len().saturating_sub(1) * ITEM_HEIGHT); } Ok(()) }