diff --git a/benches/results_list_benchmark.rs b/benches/results_list_benchmark.rs index 61e9857..ec80260 100644 --- a/benches/results_list_benchmark.rs +++ b/benches/results_list_benchmark.rs @@ -8,6 +8,7 @@ use television_channels::entry::merge_ranges; use television_channels::entry::{Entry, PreviewType}; use television_screen::colors::ResultsColorscheme; use television_screen::results::build_results_list; + pub fn results_list_benchmark(c: &mut Criterion) { let mut icon_color_cache = std::collections::HashMap::default(); // FIXME: there's probably a way to have this as a benchmark asset @@ -17,7 +18,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/LICENSE".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -34,7 +35,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/README.md".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -51,7 +52,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/re.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -68,7 +69,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/io.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -85,7 +86,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/gc.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -102,7 +103,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/uu.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -119,7 +120,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/nt.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -136,7 +137,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/dis.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -153,7 +154,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/imp.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -170,7 +171,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/bdb.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -187,7 +188,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/abc.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -204,7 +205,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/cgi.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -221,7 +222,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/bz2.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -238,7 +239,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/grp.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -255,7 +256,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/ast.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -272,7 +273,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/csv.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -289,7 +290,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/pdb.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -306,7 +307,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/pwd.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -323,7 +324,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/ssl.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -340,7 +341,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/tty.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -357,7 +358,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/nis.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -374,7 +375,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/pty.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -391,7 +392,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/cmd.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -408,7 +409,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/tests/utils.py".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -425,7 +426,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/pyproject.toml".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -442,7 +443,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/MAINTAINERS.md".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -459,7 +460,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/enum.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -476,7 +477,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/hmac.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -493,7 +494,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/uuid.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -510,7 +511,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/glob.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -527,7 +528,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/_ast.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -544,7 +545,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/_csv.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -561,7 +562,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/code.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -578,7 +579,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/spwd.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -595,7 +596,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { Entry { name: "typeshed/stdlib/_msi.pyi".to_string(), value: None, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -619,7 +620,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { }), line_number: None, preview_type: PreviewType::Files, - name_match_ranges: Some(merge_ranges(&vec![ + name_match_ranges: Some(merge_ranges(&[ (0, 1), (1, 2), (2, 3), @@ -655,7 +656,7 @@ pub fn results_list_benchmark(c: &mut Criterion) { &mut icon_color_cache, &colorscheme, ); - }) + }); }); } diff --git a/crates/television-channels/src/cable.rs b/crates/television-channels/src/cable.rs index 638e360..5a01024 100644 --- a/crates/television-channels/src/cable.rs +++ b/crates/television-channels/src/cable.rs @@ -15,6 +15,7 @@ pub struct CableChannelPrototype { pub const DEFAULT_DELIMITER: &str = " "; +#[allow(clippy::unnecessary_wraps)] fn default_delimiter() -> Option { Some(DEFAULT_DELIMITER.to_string()) } diff --git a/crates/television-channels/src/channels/alias.rs b/crates/television-channels/src/channels/alias.rs index 953b4c5..2cd6249 100644 --- a/crates/television-channels/src/channels/alias.rs +++ b/crates/television-channels/src/channels/alias.rs @@ -89,18 +89,17 @@ impl OnAir for Channel { .with_icon(self.file_icon); if should_add_name_indices { - entry = entry.with_name_match_ranges( - name_indices.into_iter().map(|i| (i, i + 1)).collect(), - ); + let name_indices: Vec<(u32, u32)> = + name_indices.into_iter().map(|i| (i, i + 1)).collect(); + entry = entry.with_name_match_ranges(&name_indices); } if should_add_value_indices { - entry = entry.with_value_match_ranges( - value_indices - .into_iter() - .map(|i| (i, i + 1)) - .collect(), - ); + let value_indices: Vec<(u32, u32)> = value_indices + .into_iter() + .map(|i| (i, i + 1)) + .collect(); + entry = entry.with_value_match_ranges(&value_indices); } entry diff --git a/crates/television-channels/src/channels/cable.rs b/crates/television-channels/src/channels/cable.rs index 66a1afe..f664e7b 100644 --- a/crates/television-channels/src/channels/cable.rs +++ b/crates/television-channels/src/channels/cable.rs @@ -141,7 +141,7 @@ impl OnAir for Channel { PreviewKind::None => PreviewType::None, }, ) - .with_name_match_ranges(item.match_indices) + .with_name_match_ranges(&item.match_indices) }) .collect() } diff --git a/crates/television-channels/src/channels/dirs.rs b/crates/television-channels/src/channels/dirs.rs index 01b657c..6ad2cb6 100644 --- a/crates/television-channels/src/channels/dirs.rs +++ b/crates/television-channels/src/channels/dirs.rs @@ -84,7 +84,7 @@ impl OnAir for Channel { " ", )), ) - .with_name_match_ranges(item.match_indices) + .with_name_match_ranges(&item.match_indices) .with_icon(FileIcon::from(&path)) }) .collect() diff --git a/crates/television-channels/src/channels/env.rs b/crates/television-channels/src/channels/env.rs index 99a1f6c..3f5f925 100644 --- a/crates/television-channels/src/channels/env.rs +++ b/crates/television-channels/src/channels/env.rs @@ -69,18 +69,17 @@ impl OnAir for Channel { .with_icon(self.file_icon); if should_add_name_indices { - entry = entry.with_name_match_ranges( - name_indices.into_iter().map(|i| (i, i + 1)).collect(), - ); + let name_indices: Vec<(u32, u32)> = + name_indices.into_iter().map(|i| (i, i + 1)).collect(); + entry = entry.with_name_match_ranges(&name_indices); } if should_add_value_indices { - entry = entry.with_value_match_ranges( - value_indices - .into_iter() - .map(|i| (i, i + 1)) - .collect(), - ); + let value_indices: Vec<(u32, u32)> = value_indices + .into_iter() + .map(|i| (i, i + 1)) + .collect(); + entry = entry.with_value_match_ranges(&value_indices); } entry diff --git a/crates/television-channels/src/channels/files.rs b/crates/television-channels/src/channels/files.rs index ff76a32..c52f91f 100644 --- a/crates/television-channels/src/channels/files.rs +++ b/crates/television-channels/src/channels/files.rs @@ -92,7 +92,7 @@ impl OnAir for Channel { .map(|item| { let path = item.matched_string; Entry::new(path.clone(), PreviewType::Files) - .with_name_match_ranges(item.match_indices) + .with_name_match_ranges(&item.match_indices) .with_icon(FileIcon::from(&path)) }) .collect() diff --git a/crates/television-channels/src/channels/git_repos.rs b/crates/television-channels/src/channels/git_repos.rs index da175dc..1afa2f6 100644 --- a/crates/television-channels/src/channels/git_repos.rs +++ b/crates/television-channels/src/channels/git_repos.rs @@ -64,7 +64,7 @@ impl OnAir for Channel { path.clone(), PreviewType::Command(PREVIEW_COMMAND.clone()), ) - .with_name_match_ranges(item.match_indices) + .with_name_match_ranges(&item.match_indices) .with_icon(self.icon) }) .collect() diff --git a/crates/television-channels/src/channels/remote_control.rs b/crates/television-channels/src/channels/remote_control.rs index e5e2b6c..4579744 100644 --- a/crates/television-channels/src/channels/remote_control.rs +++ b/crates/television-channels/src/channels/remote_control.rs @@ -131,7 +131,7 @@ impl OnAir for RemoteControl { .map(|item| { let path = item.matched_string; Entry::new(path, PreviewType::Basic) - .with_name_match_ranges(item.match_indices) + .with_name_match_ranges(&item.match_indices) .with_icon(match item.inner { RCButton::Channel(_) => TV_ICON, RCButton::CableChannel(_) => CABLE_ICON, diff --git a/crates/television-channels/src/channels/stdin.rs b/crates/television-channels/src/channels/stdin.rs index 2fb1581..c0020d0 100644 --- a/crates/television-channels/src/channels/stdin.rs +++ b/crates/television-channels/src/channels/stdin.rs @@ -79,7 +79,7 @@ impl OnAir for Channel { // NOTE: we're passing `PreviewType::Basic` here just as a placeholder // to avoid storing the preview command multiple times for each item. Entry::new(item.matched_string, PreviewType::Basic) - .with_name_match_ranges(item.match_indices) + .with_name_match_ranges(&item.match_indices) }) .collect() } diff --git a/crates/television-channels/src/channels/text.rs b/crates/television-channels/src/channels/text.rs index d858a96..7fa7952 100644 --- a/crates/television-channels/src/channels/text.rs +++ b/crates/television-channels/src/channels/text.rs @@ -179,7 +179,7 @@ impl OnAir for Channel { item.inner.path.to_string_lossy().to_string(); Entry::new(display_path, PreviewType::Files) .with_value(line) - .with_value_match_ranges(item.match_indices) + .with_value_match_ranges(&item.match_indices) .with_icon(FileIcon::from(item.inner.path.as_path())) .with_line_number(item.inner.line_number) }) diff --git a/crates/television-channels/src/entry.rs b/crates/television-channels/src/entry.rs index 77c58ee..d072d29 100644 --- a/crates/television-channels/src/entry.rs +++ b/crates/television-channels/src/entry.rs @@ -56,8 +56,8 @@ impl Entry { /// /// let entry = Entry::new("name".to_string(), PreviewType::EnvVar) /// .with_value("value".to_string()) - /// .with_name_match_ranges(vec![(0, 1)]) - /// .with_value_match_ranges(vec![(0, 1)]) + /// .with_name_match_ranges(&vec![(0, 1)]) + /// .with_value_match_ranges(&vec![(0, 1)]) /// .with_icon(FileIcon::default()) /// .with_line_number(0); /// ``` @@ -88,17 +88,17 @@ impl Entry { pub fn with_name_match_ranges( mut self, - name_match_ranges: Vec<(u32, u32)>, + name_match_ranges: &[(u32, u32)], ) -> Self { - self.name_match_ranges = Some(merge_ranges(&name_match_ranges)); + self.name_match_ranges = Some(merge_ranges(name_match_ranges)); self } pub fn with_value_match_ranges( mut self, - value_match_ranges: Vec<(u32, u32)>, + value_match_ranges: &[(u32, u32)], ) -> Self { - self.value_match_ranges = Some(merge_ranges(&value_match_ranges)); + self.value_match_ranges = Some(merge_ranges(value_match_ranges)); self } @@ -154,7 +154,7 @@ impl PreviewCommand { impl Display for PreviewCommand { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self) + write!(f, "{self:?}") } } diff --git a/crates/television-previewers/src/ansi.rs b/crates/television-previewers/src/ansi.rs index eb8825f..893e3dd 100644 --- a/crates/television-previewers/src/ansi.rs +++ b/crates/television-previewers/src/ansi.rs @@ -10,7 +10,7 @@ pub mod parser; pub use error::Error; use tui::text::Text; -/// IntoText will convert any type that has a AsRef<[u8]> to a Text. +/// `IntoText` will convert any type that has a `AsRef<[u8]>` to a Text. pub trait IntoText { /// Convert the type to a Text. #[allow(clippy::wrong_self_convention)] diff --git a/crates/television-previewers/src/ansi/code.rs b/crates/television-previewers/src/ansi/code.rs index 6f3e82f..52305a0 100644 --- a/crates/television-previewers/src/ansi/code.rs +++ b/crates/television-previewers/src/ansi/code.rs @@ -1,10 +1,10 @@ use tui::style::Color; -/// This enum stores most types of ansi escape sequences +/// This enum stores most types of ansi escape sequences /// /// You can turn an escape sequence to this enum variant using -/// AnsiCode::from(code: u8) -/// This doesn't support all of them but does support most of them. +/// `AnsiCode::from(code: u8)` +/// This doesn't support all of them but does support most of them. #[derive(Debug, PartialEq, Clone)] #[non_exhaustive] @@ -124,6 +124,7 @@ impl From for AnsiCode { 94 => AnsiCode::ForegroundColor(Color::LightBlue), 95 => AnsiCode::ForegroundColor(Color::LightMagenta), 96 => AnsiCode::ForegroundColor(Color::LightCyan), + #[allow(clippy::match_same_arms)] 97 => AnsiCode::ForegroundColor(Color::White), 100 => AnsiCode::BackgroundColor(Color::DarkGray), 101 => AnsiCode::BackgroundColor(Color::LightRed), diff --git a/crates/television-previewers/src/ansi/parser.rs b/crates/television-previewers/src/ansi/parser.rs index cabad8b..4699447 100644 --- a/crates/television-previewers/src/ansi/parser.rs +++ b/crates/television-previewers/src/ansi/parser.rs @@ -48,32 +48,32 @@ impl From for tui::style::Style { .remove_modifier(Modifier::DIM); } AnsiCode::Italic => { - style = style.add_modifier(Modifier::ITALIC) + style = style.add_modifier(Modifier::ITALIC); } AnsiCode::Underline => { - style = style.add_modifier(Modifier::UNDERLINED) + style = style.add_modifier(Modifier::UNDERLINED); } AnsiCode::SlowBlink => { - style = style.add_modifier(Modifier::SLOW_BLINK) + style = style.add_modifier(Modifier::SLOW_BLINK); } AnsiCode::RapidBlink => { - style = style.add_modifier(Modifier::RAPID_BLINK) + style = style.add_modifier(Modifier::RAPID_BLINK); } AnsiCode::Reverse => { - style = style.add_modifier(Modifier::REVERSED) + style = style.add_modifier(Modifier::REVERSED); } AnsiCode::Conceal => { - style = style.add_modifier(Modifier::HIDDEN) + style = style.add_modifier(Modifier::HIDDEN); } AnsiCode::CrossedOut => { - style = style.add_modifier(Modifier::CROSSED_OUT) + style = style.add_modifier(Modifier::CROSSED_OUT); } AnsiCode::DefaultForegroundColor => { - style = style.fg(Color::Reset) + style = style.fg(Color::Reset); } AnsiCode::SetForegroundColor => { if let Some(color) = item.color { - style = style.fg(color) + style = style.fg(color); } } AnsiCode::ForegroundColor(color) => style = style.fg(color), @@ -84,13 +84,14 @@ impl From for tui::style::Style { } } +#[allow(clippy::unnecessary_wraps)] pub(crate) fn text(mut s: &[u8]) -> IResult<&[u8], Text<'static>> { let mut lines = Vec::new(); let mut last = Style::new(); - while let Ok((_s, (line, style))) = line(last)(s) { + while let Ok((c, (line, style))) = line(last)(s) { lines.push(line); last = style; - s = _s; + s = c; if s.is_empty() { break; } @@ -99,13 +100,14 @@ pub(crate) fn text(mut s: &[u8]) -> IResult<&[u8], Text<'static>> { } #[cfg(feature = "zero-copy")] +#[allow(clippy::unnecessary_wraps)] pub(crate) fn text_fast(mut s: &[u8]) -> IResult<&[u8], Text<'_>> { let mut lines = Vec::new(); let mut last = Style::new(); - while let Ok((_s, (line, style))) = line_fast(last)(s) { + while let Ok((c, (line, style))) = line_fast(last)(s) { lines.push(line); last = style; - s = _s; + s = c; if s.is_empty() { break; } diff --git a/crates/television-previewers/src/previewers/env.rs b/crates/television-previewers/src/previewers/env.rs index 67ac1f6..768fd0d 100644 --- a/crates/television-previewers/src/previewers/env.rs +++ b/crates/television-previewers/src/previewers/env.rs @@ -47,7 +47,7 @@ const PATH: &str = "PATH"; fn maybe_add_newline_after_colon(s: &str, name: &str) -> String { if name.contains(PATH) { - return s.replace(":", "\n"); + return s.replace(':', "\n"); } s.to_string() } diff --git a/crates/television-previewers/src/previewers/files.rs b/crates/television-previewers/src/previewers/files.rs index bd0920d..935c763 100644 --- a/crates/television-previewers/src/previewers/files.rs +++ b/crates/television-previewers/src/previewers/files.rs @@ -125,8 +125,8 @@ impl FilePreviewer { } #[allow(dead_code)] - fn cache_preview(&mut self, key: String, preview: Arc) { - self.cache.lock().insert(key, &preview); + fn cache_preview(&mut self, key: String, preview: &Arc) { + self.cache.lock().insert(key, preview); } } diff --git a/crates/television-screen/src/input.rs b/crates/television-screen/src/input.rs index bb1892a..f2234d0 100644 --- a/crates/television-screen/src/input.rs +++ b/crates/television-screen/src/input.rs @@ -55,7 +55,7 @@ pub fn draw_input_box( Constraint::Fill(1), // result count Constraint::Length( - 3 * ((total_count as f32).log10().ceil() as u16 + 1) + 3, + 3 * (u16::try_from((total_count).ilog10()).unwrap() + 1) + 3, ), // spinner Constraint::Length(1), diff --git a/crates/television-screen/src/preview.rs b/crates/television-screen/src/preview.rs index 528b9a8..b1ee114 100644 --- a/crates/television-screen/src/preview.rs +++ b/crates/television-screen/src/preview.rs @@ -27,6 +27,7 @@ use television_utils::strings::{ const FILL_CHAR_SLANTED: char = '╱'; const FILL_CHAR_EMPTY: char = ' '; +#[allow(clippy::needless_pass_by_value)] pub fn build_preview_paragraph( preview_block: Block<'_>, inner: Rect, @@ -89,6 +90,7 @@ pub fn build_preview_paragraph( } } +#[allow(clippy::needless_pass_by_value)] fn build_ansi_text_paragraph( text: String, preview_block: Block, @@ -110,6 +112,7 @@ fn build_ansi_text_paragraph( .scroll((preview_scroll, 0)) } +#[allow(clippy::needless_pass_by_value)] fn build_plain_text_paragraph( text: Vec, preview_block: Block<'_>, @@ -151,6 +154,7 @@ fn build_plain_text_paragraph( .scroll((preview_scroll, 0)) } +#[allow(clippy::needless_pass_by_value)] fn build_plain_text_wrapped_paragraph( text: String, preview_block: Block<'_>, @@ -169,6 +173,7 @@ fn build_plain_text_wrapped_paragraph( .wrap(Wrap { trim: true }) } +#[allow(clippy::needless_pass_by_value)] fn build_syntect_highlighted_paragraph( highlighted_lines: Vec>, preview_block: Block, diff --git a/crates/television/cli.rs b/crates/television/cli.rs index 3e44814..9e443e3 100644 --- a/crates/television/cli.rs +++ b/crates/television/cli.rs @@ -273,6 +273,7 @@ pub fn guess_channel_from_prompt( Err(eyre!("No channel found for prompt: {}", prompt)) } +#[allow(clippy::unnecessary_wraps)] fn delimiter_parser(s: &str) -> Result { Ok(match s { "" => ":".to_string(), diff --git a/crates/television/config/keybindings.rs b/crates/television/config/keybindings.rs index 55dfc90..e42eca7 100644 --- a/crates/television/config/keybindings.rs +++ b/crates/television/config/keybindings.rs @@ -16,10 +16,12 @@ pub enum Binding { impl Display for Binding { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Binding::SingleKey(key) => write!(f, "{}", key), + Binding::SingleKey(key) => write!(f, "{key}"), Binding::MultipleKeys(keys) => { - let keys_str: Vec = - keys.iter().map(|k| k.to_string()).collect(); + let keys_str: Vec = keys + .iter() + .map(std::string::ToString::to_string) + .collect(); write!(f, "{}", keys_str.join(", ")) } } diff --git a/crates/television/television.rs b/crates/television/television.rs index daadb4c..ec55ce2 100644 --- a/crates/television/television.rs +++ b/crates/television/television.rs @@ -256,6 +256,7 @@ impl Television { Ok(()) } + #[allow(clippy::unused_async)] /// Update the state of the component based on a received action. /// /// # Arguments diff --git a/crates/television/tui.rs b/crates/television/tui.rs index ef5cd46..2d40ba9 100644 --- a/crates/television/tui.rs +++ b/crates/television/tui.rs @@ -108,7 +108,7 @@ where { fn drop(&mut self) { match self.exit() { - Ok(_) => debug!("Successfully exited terminal"), + Ok(()) => debug!("Successfully exited terminal"), Err(e) => debug!("Failed to exit terminal: {:?}", e), } }