From 8d6db24bad546a5b6671b868e33838e3b67f5c66 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 5 Dec 2021 07:36:35 +0000 Subject: [PATCH] tidy clippy linting --- .clippy.toml | 1 + .github/workflows/ci.yml | 1 - src/lib.rs | 3 +++ src/paging.rs | 6 +++--- src/prompts/confirm.rs | 8 ++++---- src/prompts/multi_select.rs | 6 +++--- src/prompts/select.rs | 4 ++-- src/prompts/sort.rs | 4 ++-- src/theme.rs | 11 ++++++----- 9 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 .clippy.toml diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 00000000..434e968a --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +msrv = "1.51.0" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 516bf5c3..5dbc6cd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,6 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: -- -D warnings - name: Format check uses: actions-rs/cargo@v1 with: diff --git a/src/lib.rs b/src/lib.rs index 26425810..6ea265ad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,9 @@ //! * Other kind of prompts //! * Editor launching +#![deny(clippy::all)] +#![warn(clippy::pedantic)] + #[cfg(feature = "completion")] pub use completion::Completion; pub use console; diff --git a/src/paging.rs b/src/paging.rs index 581036f7..dd703e9f 100644 --- a/src/paging.rs +++ b/src/paging.rs @@ -59,13 +59,13 @@ impl<'a> Paging<'a> { self.pages = (self.items_len as f64 / self.capacity as f64).ceil() as usize; } - if self.active != (self.pages > 1) { + if self.active == (self.pages > 1) { + self.activity_transition = false; + } else { self.active = self.pages > 1; self.activity_transition = true; // Clear everything to prevent "ghost" lines in terminal when a resize happened self.term.clear_last_lines(self.capacity)?; - } else { - self.activity_transition = false; } if cursor_pos != !0 diff --git a/src/prompts/confirm.rs b/src/prompts/confirm.rs index 37222976..f8583298 100644 --- a/src/prompts/confirm.rs +++ b/src/prompts/confirm.rs @@ -98,8 +98,8 @@ impl Confirm<'_> { /// /// The dialog is rendered on stderr. /// - /// Result contains `bool` if user answered "yes" or "no" or `default` (configured in [default](#method.default)) if pushes enter. - /// This unlike [interact_opt](#method.interact_opt) does not allow to quit with 'Esc' or 'q'. + /// Result contains `bool` if user answered "yes" or "no" or `default` (configured in [`default`](Confirm::default) if pushes enter. + /// This unlike [`interact_opt`](Self::interact_opt) does not allow to quit with 'Esc' or 'q'. #[inline] pub fn interact(&self) -> io::Result { self.interact_on(&Term::stderr()) @@ -109,7 +109,7 @@ impl Confirm<'_> { /// /// The dialog is rendered on stderr. /// - /// Result contains `Some(bool)` if user answered "yes" or "no" or `Some(default)` (configured in [default](#method.default)) if pushes enter, + /// Result contains `Some(bool)` if user answered "yes" or "no" or `Some(default)` (configured in [`default`](Confirm::default)) if pushes enter, /// or `None` if user cancelled with 'Esc' or 'q'. #[inline] pub fn interact_opt(&self) -> io::Result> { @@ -137,7 +137,7 @@ impl Confirm<'_> { .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Quit not allowed in this case")) } - /// Like [interact_opt](#method.interact_opt) but allows a specific terminal to be set. + /// Like [`interact_opt`](Self::interact_opt) but allows a specific terminal to be set. /// /// ## Examples /// ```rust,no_run diff --git a/src/prompts/multi_select.rs b/src/prompts/multi_select.rs index 4d055879..f697c3c2 100644 --- a/src/prompts/multi_select.rs +++ b/src/prompts/multi_select.rs @@ -58,7 +58,7 @@ impl MultiSelect<'_> { self.defaults = val .to_vec() .iter() - .cloned() + .copied() .chain(repeat(false)) .take(self.items.len()) .collect(); @@ -130,7 +130,7 @@ impl MultiSelect<'_> { /// The user can select the items with the 'Space' bar and on 'Enter' the indices of selected items will be returned. /// The dialog is rendered on stderr. /// Result contains `Vec` if user hit 'Enter'. - /// This unlike [interact_opt](#method.interact_opt) does not allow to quit with 'Esc' or 'q'. + /// This unlike [`interact_opt`](Self::interact_opt) does not allow to quit with 'Esc' or 'q'. #[inline] pub fn interact(&self) -> io::Result> { self.interact_on(&Term::stderr()) @@ -170,7 +170,7 @@ impl MultiSelect<'_> { .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Quit not allowed in this case")) } - /// Like [interact_opt](#method.interact_opt) but allows a specific terminal to be set. + /// Like [`interact_opt`](Self::interact_opt) but allows a specific terminal to be set. /// /// ## Examples /// ```rust,no_run diff --git a/src/prompts/select.rs b/src/prompts/select.rs index c616bbb9..bc332a82 100644 --- a/src/prompts/select.rs +++ b/src/prompts/select.rs @@ -167,7 +167,7 @@ impl Select<'_> { /// The user can select the items with the 'Space' bar or 'Enter' and the index of selected item will be returned. /// The dialog is rendered on stderr. /// Result contains `index` if user selected one of items using 'Enter'. - /// This unlike [interact_opt](#method.interact_opt) does not allow to quit with 'Esc' or 'q'. + /// This unlike [`interact_opt`](Self::interact_opt) does not allow to quit with 'Esc' or 'q'. #[inline] pub fn interact(&self) -> io::Result { self.interact_on(&Term::stderr()) @@ -207,7 +207,7 @@ impl Select<'_> { .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Quit not allowed in this case")) } - /// Like [interact_opt](#method.interact_opt) but allows a specific terminal to be set. + /// Like [`interact_opt`](Self::interact_opt) but allows a specific terminal to be set. /// /// ## Examples /// ```rust,no_run diff --git a/src/prompts/sort.rs b/src/prompts/sort.rs index 5902d696..4370d895 100644 --- a/src/prompts/sort.rs +++ b/src/prompts/sort.rs @@ -102,7 +102,7 @@ impl Sort<'_> { /// The user can order the items with the 'Space' bar and the arrows. On 'Enter' ordered list of the incides of items will be returned. /// The dialog is rendered on stderr. /// Result contains `Vec` if user hit 'Enter'. - /// This unlike [interact_opt](#method.interact_opt) does not allow to quit with 'Esc' or 'q'. + /// This unlike [`interact_opt`](Self::interact_opt) does not allow to quit with 'Esc' or 'q'. #[inline] pub fn interact(&self) -> io::Result> { self.interact_on(&Term::stderr()) @@ -142,7 +142,7 @@ impl Sort<'_> { .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Quit not allowed in this case")) } - /// Like [interact_opt](#method.interact_opt) but allows a specific terminal to be set. + /// Like [`interact_opt`](Self::interact_opt) but allows a specific terminal to be set. /// /// ## Examples /// ```rust,no_run diff --git a/src/theme.rs b/src/theme.rs index 29b1aabc..43ea7a01 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -506,15 +506,16 @@ impl Theme for ColorfulTheme { text: &str, active: bool, ) -> fmt::Result { - let details = match active { - true => ( + let details = if active { + ( &self.active_item_prefix, self.active_item_style.apply_to(text), - ), - false => ( + ) + } else { + ( &self.inactive_item_prefix, self.inactive_item_style.apply_to(text), - ), + ) }; write!(f, "{} {}", details.0, details.1)