tlc: fix all 49 clippy warnings (0 remaining)

Systematic clippy sweep across 22 files:
- Remove unused imports (Modifier, Block, Borders, Clear, Line)
- Remove unnecessary mut/unused variables (cursor.rs, mc_skin.rs)
- Fix unnecessary casts in popup.rs and viewer/mod.rs
- Use abs_diff instead of manual abs pattern (render.rs)
- Collapse nested if in menubar.rs
- Merge identical if branches in render.rs
- Use strip_prefix instead of manual slice (mod.rs)
- Use io::Error::other instead of Error::new (source.rs)
- Remove useless format! in known_hosts.rs
- Add #[derive(Default)] to SelectionMode enum
- Add #[allow] for too_many_arguments on render functions
- Add #[allow(dead_code)] for utility functions (centered_rect, rgb)
- Remove redundant .clone() on &str in menubar.rs
- Remove .max(0) on unsigned subtraction (button.rs)
- Add missing doc comments on public methods (editor, panel, ops)

cargo clippy --lib: 0 warnings (was 49)
cargo test --lib: 1213 passed, 0 failed
This commit is contained in:
2026-07-05 07:42:00 +03:00
parent fb9be0d293
commit 4e3b06af83
22 changed files with 52 additions and 49 deletions
@@ -32,18 +32,15 @@ use crate::editor::buffer::Buffer;
/// (line, column) corner and extending to another (line, column)
/// corner. Matches Alt+Arrow (MC `MarkColumn*` bindings).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Default)]
pub enum SelectionMode {
/// Contiguous text range — the legacy "Shift+Arrow" behaviour.
#[default]
Stream,
/// Rectangular block — Alt+Arrow / Alt-PageUp / Alt-PageDown.
Column,
}
impl Default for SelectionMode {
fn default() -> Self {
Self::Stream
}
}
/// A rectangular column selection: `(start_line, start_col,
/// end_line, end_col)` in **visual** (tab-expanded) column coordinates.
@@ -261,11 +258,9 @@ impl Cursor {
// Build the post-delete text by walking line-by-line and
// stripping the rectangle columns from each line.
let mut new_text = String::with_capacity(text.len());
let mut byte_pos = 0usize;
for line in 0..buf.line_count() {
let line_start = buf.line_offset(line);
let line_len = buf.line_length(line);
let _ = byte_pos;
if line > 0 {
new_text.push('\n');
}
@@ -359,12 +359,12 @@ impl EditorMenuBar {
self.active_menu -= 1;
}
self.selected_item = 0;
return Handled;
Handled
}
RIGHT => {
self.active_menu = (self.active_menu + 1) % self.menus.len();
self.selected_item = 0;
return Handled;
Handled
}
UP => {
let items = &self.menus[self.active_menu].items;
@@ -378,7 +378,7 @@ impl EditorMenuBar {
break;
}
}
return Handled;
Handled
}
DOWN => {
let items = &self.menus[self.active_menu].items;
@@ -388,16 +388,17 @@ impl EditorMenuBar {
break;
}
}
return Handled;
Handled
}
c if c == Key::ENTER.code => {
let menu = &self.menus[self.active_menu];
let item = &menu.items[self.selected_item];
let cmd = item.cmd;
if matches!(cmd, EditorCmd::Nop) {
return Handled;
Handled
} else {
Dispatch(cmd)
}
return Dispatch(cmd);
}
_ => {
if let Some(ch) = Self::key_to_char(key) {
@@ -422,10 +423,8 @@ impl EditorMenuBar {
/// Decode a printable ASCII letter from a Key (if any). Returns
/// `None` for non-letter keys.
fn key_to_char(key: Key) -> Option<char> {
if key.code >= 0x20 && key.code <= 0x7E {
if key.mods.is_empty() {
return Some(key.code as u8 as char);
}
if key.code >= 0x20 && key.code <= 0x7E && key.mods.is_empty() {
return Some(key.code as u8 as char);
}
None
}
@@ -649,21 +649,25 @@ bracket_flash: None,
self.word_wrap
}
/// Whether auto-indent is enabled on Enter.
#[must_use]
pub fn auto_indent(&self) -> bool {
self.auto_indent
}
/// Toggle auto-indent and return the new state.
pub fn toggle_auto_indent(&mut self) -> bool {
self.auto_indent = !self.auto_indent;
self.auto_indent
}
/// Whether whitespace glyphs are visible.
#[must_use]
pub fn show_whitespace(&self) -> bool {
self.show_whitespace
}
/// Toggle whitespace visibility and return the new state.
pub fn toggle_show_whitespace(&mut self) -> bool {
self.show_whitespace = !self.show_whitespace;
self.show_whitespace
@@ -1174,8 +1178,8 @@ bracket_flash: None,
for line in segment.split_inclusive('\n') {
let content = line.strip_suffix('\n').unwrap_or(line);
let nl = if line.ends_with('\n') { "\n" } else { "" };
if content.starts_with('\t') {
new_segment.push_str(&content[1..]);
if let Some(stripped) = content.strip_prefix('\t') {
new_segment.push_str(stripped);
removed += 1;
} else {
let spaces = content.bytes().take_while(|&b| b == b' ').count().min(8);
@@ -207,11 +207,7 @@ impl Editor {
if cursor_line == line_idx {
format!("{:>w$}", n, w = (gutter_w - 1) as usize)
} else {
let d = if line_idx < cursor_line {
cursor_line - line_idx
} else {
line_idx - cursor_line
};
let d = line_idx.abs_diff(cursor_line);
format!("{:>w$}", d, w = (gutter_w - 1) as usize)
}
} else {
@@ -437,7 +433,7 @@ impl Editor {
let popup_h = (window_end - scroll_offset) as u16 + 2;
let popup_w = body_area.width.min(40);
let row_y = cursor_pos.map(|(_, y)| y).unwrap_or(body_area.y);
let desired_y = if row_y.saturating_sub(body_area.y) >= popup_h + 1 {
let desired_y = if row_y.saturating_sub(body_area.y) > popup_h {
row_y - popup_h
} else {
row_y + 1
@@ -808,6 +804,7 @@ impl Editor {
}
}
#[allow(clippy::too_many_arguments)]
fn paint_scrollbar(
buf: &mut ratatui::buffer::Buffer,
area: Rect,
@@ -888,6 +885,7 @@ fn paint_cursor_shape(
}
}
#[allow(clippy::too_many_arguments)]
fn push_rendered_text<'a>(
spans: &mut Vec<Span<'a>>,
text: &str,
@@ -1048,9 +1046,7 @@ fn build_wrap_map(
let chars = buffer.line_length_chars(line_idx);
// Empty line is always at least one visual row so the user
// sees the `~` tilde marker.
let rows = if body_width == 0 {
1
} else if chars == 0 {
let rows = if body_width == 0 || chars == 0 {
1
} else {
chars.div_ceil(body_width).max(1)
@@ -260,7 +260,7 @@ impl SearchState {
len,
) {
Some(m) => {
let next = if m.len() == 0 { pos + 1 } else { m.range.end };
let next = if m.is_empty() { pos + 1 } else { m.range.end };
out.push(m);
pos = next;
}
@@ -3,7 +3,7 @@
use crate::key::Key;
use crate::terminal::color::Theme;
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
use ratatui::style::{Modifier, Style};
use ratatui::style::Style;
use ratatui::text::{Line, Span};
use ratatui::widgets::Paragraph;
use ratatui::Frame;
@@ -17,7 +17,7 @@
use std::path::PathBuf;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Modifier, Style};
use ratatui::style::Style;
use ratatui::text::{Line, Span};
use ratatui::widgets::Paragraph;
use ratatui::Frame;
@@ -7,7 +7,7 @@
use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
use ratatui::widgets::{Clear, Paragraph};
use ratatui::Frame;
use crate::key::Key;
@@ -356,7 +356,7 @@ impl MenuBar {
let y = 1u16;
let dropdown_area = Rect::new(x, y, dropdown_w, dropdown_h);
let inner = render_popup(frame, dropdown_area, menu.title.clone(), theme);
let inner = render_popup(frame, dropdown_area, menu.title, theme);
let chunks = Layout::default()
.direction(Direction::Vertical)
@@ -12,7 +12,7 @@
use std::path::PathBuf;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Modifier, Style};
use ratatui::style::Style;
use ratatui::text::{Line, Span};
use ratatui::widgets::{Paragraph, Wrap};
use ratatui::Frame;
@@ -241,6 +241,7 @@ impl OwnerDialog {
}
}
#[allow(dead_code)]
fn centered_rect(area: Rect, width_pct: f32, height_pct: f32) -> Rect {
let w = (area.width as f32 * width_pct.clamp(0.1, 1.0)) as u16;
let h = (area.height as f32 * height_pct.clamp(0.1, 1.0)) as u16;
@@ -359,16 +359,19 @@ impl Panel {
/// Current sort-reverse state.
#[must_use]
/// Whether reverse sort is enabled.
pub fn sort_reverse(&self) -> bool {
self.sort_reverse
}
/// Toggle case-sensitive sort and re-sort.
pub fn toggle_sort_case(&mut self) {
self.sort_case_sensitive = !self.sort_case_sensitive;
self.sort_in_place();
}
#[must_use]
/// Whether case-sensitive sort is enabled.
pub fn sort_case_sensitive(&self) -> bool {
self.sort_case_sensitive
}
@@ -385,10 +388,12 @@ impl Panel {
}
#[must_use]
/// Current sort field.
pub fn sort_field(&self) -> SortField {
self.sort_field
}
/// Apply a sort field and direction.
pub fn apply_sort(&mut self, field: SortField, reverse: bool) {
self.sort_field = field;
self.sort_reverse = reverse;
@@ -4,9 +4,9 @@
//! the pattern is returned; on Esc the dialog is cancelled.
use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use ratatui::style::{Modifier, Style};
use ratatui::style::Style;
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
use ratatui::widgets::Paragraph;
use ratatui::Frame;
use crate::key::Key;
@@ -337,6 +337,7 @@ impl PermissionDialog {
}
}
#[allow(dead_code)]
fn centered_rect(area: Rect, width_pct: f32, height_pct: f32) -> Rect {
let w = (area.width as f32 * width_pct.clamp(0.1, 1.0)) as u16;
let h = (area.height as f32 * height_pct.clamp(0.1, 1.0)) as u16;
@@ -168,6 +168,7 @@ pub struct HardlinkTracker {
impl HardlinkTracker {
#[must_use]
/// Create an empty hardlink tracker.
pub fn new() -> Self {
Self::default()
}
@@ -163,6 +163,7 @@ impl Default for ProgressDialog {
}
}
#[allow(dead_code)]
fn centered_rect(area: Rect, width_pct: f32, height_pct: f32) -> Rect {
let w = (area.width as f32 * width_pct.clamp(0.1, 1.0)) as u16;
let h = (area.height as f32 * height_pct.clamp(0.1, 1.0)) as u16;
@@ -38,6 +38,7 @@ use ratatui::style::Color;
use super::mc_skin;
/// Construct a [`Color::Rgb`] from a hex constant at compile time.
#[allow(dead_code)]
const fn rgb(r: u8, g: u8, b: u8) -> Color {
Color::Rgb(r, g, b)
}
@@ -129,10 +129,10 @@ fn parse_theme(name: &'static str, text: &str) -> Theme {
let core_shadow = resolve_style(&parsed, "core", "shadow");
let status = resolve_style(&parsed, "statusbar", "_default_");
let button = resolve_style(&parsed, "buttonbar", "button");
let button_hotkey = resolve_style(&parsed, "buttonbar", "hotkey");
let _button_hotkey = resolve_style(&parsed, "buttonbar", "hotkey");
let error = resolve_style(&parsed, "error", "_default_");
let error_title = resolve_style(&parsed, "error", "errdtitle");
let dialog_default = resolve_style(&parsed, "dialog", "_default_");
let _dialog_default = resolve_style(&parsed, "dialog", "_default_");
let dialog_focus = resolve_style(&parsed, "dialog", "dfocus");
let file_directory = resolve_style(&parsed, "filehighlight", "directory");
let file_executable = resolve_style(&parsed, "filehighlight", "executable");
@@ -3,7 +3,7 @@
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::text::Span;
use ratatui::widgets::{Block, BorderType, Borders, Clear};
use ratatui::Frame;
@@ -64,14 +64,14 @@ fn render_drop_shadow(buf: &mut Buffer, area: Rect, shadow_color: ratatui::style
let x = area.x;
let rows = area.height as usize;
let cols = area.width as usize;
let right_cols = 2.min(buf.area().width.saturating_sub(x as u16 + area.width) as usize);
let right_cols = 2.min(buf.area().width.saturating_sub(x + area.width) as usize);
if right_cols == 0 && y + area.height >= buf.area().height {
return;
}
for row in 0..rows.saturating_sub(1) {
let yy = y as usize + 1 + row;
for col in 0..right_cols {
let xx = x as usize + cols as usize + col;
let xx = x as usize + cols + col;
if let Some(cell) = buf.cell_mut((xx as u16, yy as u16)) {
cell.set_bg(shadow_color);
}
@@ -79,7 +79,7 @@ fn render_drop_shadow(buf: &mut Buffer, area: Rect, shadow_color: ratatui::style
}
let bottom_y = y as usize + rows;
if bottom_y < buf.area().height as usize {
let available_cols = buf.area().width.saturating_sub(x as u16 + 2) as usize;
let available_cols = buf.area().width.saturating_sub(x + 2) as usize;
let strip_cols = cols.min(available_cols);
for col in 0..strip_cols {
let xx = x as usize + 2 + col;
@@ -232,7 +232,7 @@ pub fn entry_from_tofu(host: &str, key_type: &str, fingerprint: &str) -> KnownHo
hosts: vec![host.to_string()],
key_type: key_type.to_string(),
fingerprint: fingerprint.to_string(),
comment: Some(format!("first-seen-by-tlc")),
comment: Some("first-seen-by-tlc".to_string()),
}
}
@@ -517,7 +517,7 @@ impl Viewer {
fn footer_text(&self) -> String {
let pct = if self.goto.line_count() > 0 {
let p = (self.current_line() as u64 + 1) * 100 / self.goto.line_count() as u64;
let p = (self.current_line() + 1) * 100 / self.goto.line_count();
format!(" {}%", p.min(100))
} else {
String::new()
@@ -332,8 +332,7 @@ impl FileSource {
let bytes = match self {
Self::Inline { bytes } | Self::Compressed { bytes, .. } => bytes.as_slice(),
Self::Chunked { .. } => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
return Err(std::io::Error::other(
"save_to requires Inline or Compressed source",
));
}
@@ -120,8 +120,8 @@ pub fn render_button_row(
if specs.is_empty() || area.width == 0 || area.height == 0 {
return;
}
let mut widths: Vec<u16> = specs.iter().map(|s| button_width(*s)).collect();
let total: u16 = widths.iter().sum::<u16>() + (specs.len() as u16 - 1).max(0) * 2;
let widths: Vec<u16> = specs.iter().map(|s| button_width(*s)).collect();
let total: u16 = widths.iter().sum::<u16>() + (specs.len() as u16 - 1) * 2;
let mut x = if total < area.width {
area.x + (area.width - total) / 2
} else {
@@ -165,6 +165,7 @@ fn push_label_spans(
.position(|c| c.eq_ignore_ascii_case(&h))
.map(|i| chars[i])
});
#[allow(clippy::manual_option_zip)]
if let Some((hot_idx, hot_char)) =
hotkey_char.and_then(|hc| chars.iter().position(|c| *c == hc).map(|i| (i, hc)))
{
@@ -8,7 +8,6 @@
use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Style};
use ratatui::text::Line;
use ratatui::widgets::{Paragraph, Wrap};
use ratatui::Frame;