Skip to content

Commit

Permalink
refactor: switch lints from allow(x) to expect(x)`
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed Sep 6, 2024
1 parent 5d77f1e commit 2a0ab6d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/app_data/container_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ impl ByteStats {
}
}

#[allow(clippy::cast_precision_loss)]
#[expect(clippy::cast_precision_loss)]
impl Stats for ByteStats {
fn get_value(&self) -> f64 {
self.0 as f64
Expand Down Expand Up @@ -608,7 +608,7 @@ impl fmt::Display for ContainerItem {
}

impl ContainerItem {
#[allow(clippy::too_many_arguments)]
#[expect(clippy::too_many_arguments)]
/// Create a new container item
pub fn new(
created: u64,
Expand Down Expand Up @@ -660,7 +660,7 @@ impl ContainerItem {
}

/// Convert cpu stats into a vec for the charts function
#[allow(clippy::cast_precision_loss)]
#[expect(clippy::cast_precision_loss)]
fn get_cpu_dataset(&self) -> Vec<(f64, f64)> {
self.cpu_stats
.iter()
Expand All @@ -670,7 +670,7 @@ impl ContainerItem {
}

/// Convert mem stats into a Vec for the charts function
#[allow(clippy::cast_precision_loss)]
#[expect(clippy::cast_precision_loss)]
fn get_mem_dataset(&self) -> Vec<(f64, f64)> {
self.mem_stats
.iter()
Expand Down
4 changes: 2 additions & 2 deletions src/app_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl AppData {
}

/// Current time as unix timestamp
#[allow(clippy::expect_used)]
#[expect(clippy::expect_used)]
fn get_systemtime() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
Expand Down Expand Up @@ -933,7 +933,7 @@ impl AppData {
}

#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::many_single_char_names)]
#[expect(clippy::unwrap_used)]
mod tests {

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/app_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::app_data::DockerControls;
use std::fmt;

/// app errors to set in global state
#[allow(unused)]
#[expect(unused)]
#[derive(Debug, Clone, Copy)]
pub enum AppError {
DockerCommand(DockerControls),
Expand Down
8 changes: 4 additions & 4 deletions src/docker_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct DockerData {

impl DockerData {
/// Use docker stats to calculate current cpu usage
#[allow(clippy::cast_precision_loss)]
#[expect(clippy::cast_precision_loss)]
// TODO FIX: this can overflow
fn calculate_usage(stats: &Stats) -> f64 {
let mut cpu_percentage = 0.0;
Expand Down Expand Up @@ -349,7 +349,7 @@ impl DockerData {

/// Handle incoming messages, container controls & all container information update
/// Spawn Docker commands off into own thread
#[allow(clippy::too_many_lines)]
#[expect(clippy::too_many_lines)]
async fn message_handler(&mut self) {
while let Some(message) = self.receiver.recv().await {
let docker = Arc::clone(&self.docker);
Expand Down Expand Up @@ -505,7 +505,7 @@ mod tests {

use super::*;

#[allow(clippy::too_many_lines)]
#[expect(clippy::too_many_lines)]
fn gen_stats(x: u64, y: u64) -> Stats {
Stats {
read: String::new(),
Expand Down Expand Up @@ -623,7 +623,7 @@ mod tests {
}

#[test]
#[allow(clippy::float_cmp)]
#[expect(clippy::float_cmp)]
/// Test the stats calculator, had to cheat here to get round input/outputs
fn test_calculate_usage_no_previous_cpu() {
let stats = gen_stats(1_000_000_000, 900_000_000);
Expand Down
9 changes: 1 addition & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Only allow when debugging
// #![allow(unused)]

use app_data::AppData;
use app_error::AppError;
use bollard::{Docker, API_DEFAULT_VERSION};
Expand Down Expand Up @@ -166,12 +163,8 @@ async fn main() {
}

#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::many_single_char_names, unused)]
#[expect(clippy::unwrap_used,)]
mod tests {
use std::{
collections::{HashSet, VecDeque},
vec,
};

use bollard::service::{ContainerSummary, Port};

Expand Down
4 changes: 2 additions & 2 deletions src/parse_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tracing::error;
use crate::{ENV_KEY, ENV_VALUE};

#[derive(Parser, Debug, Clone)]
#[allow(clippy::struct_excessive_bools)]
#[expect(clippy::struct_excessive_bools)]
#[command(version, about)]
pub struct Args {
/// Docker update interval in ms, minimum effectively 1000
Expand Down Expand Up @@ -47,7 +47,7 @@ pub struct Args {
}

#[derive(Debug, Clone)]
#[allow(clippy::struct_excessive_bools)]
#[expect(clippy::struct_excessive_bools)]
pub struct CliArgs {
pub color: bool,
pub docker_interval: u32,
Expand Down
11 changes: 5 additions & 6 deletions src/ui/draw_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub fn chart(f: &mut Frame, area: Rect, app_data: &Arc<Mutex<AppData>>) {
.data(&mem.0)];

let cpu_stats = CpuStats::new(cpu.0.last().map_or(0.00, |f| f.1));
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
#[expect(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
let mem_stats = ByteStats::new(mem.0.last().map_or(0, |f| f.1 as u64));
let cpu_chart = make_chart(cpu.2, "cpu", cpu_dataset, &cpu_stats, &cpu.1);
let mem_chart = make_chart(mem.2, "memory", mem_dataset, &mem_stats, &mem.1);
Expand Down Expand Up @@ -491,7 +491,6 @@ pub fn filter_bar(area: Rect, frame: &mut Frame, app_data: &Arc<Mutex<AppData>>)

/// Draw heading bar at top of program, always visible
/// TODO Should separate into loading icon/headers/help functions
#[allow(clippy::too_many_lines)]
pub fn heading_bar(
area: Rect,
frame: &mut Frame,
Expand Down Expand Up @@ -1066,7 +1065,7 @@ fn popup(text_lines: usize, text_width: usize, r: Rect, box_location: BoxLocatio
}

#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::many_single_char_names)]
#[expect(clippy::unwrap_used)]
mod tests {

use std::{ops::RangeInclusive, sync::Arc};
Expand Down Expand Up @@ -2111,7 +2110,7 @@ mod tests {
// Charts panel //
// ************ //

#[allow(clippy::cast_precision_loss)]
#[expect(clippy::cast_precision_loss)]
// Add fixed data to the cpu & mem vecdeques
fn insert_chart_data(setup: &TuiTestSetup) {
for i in 1..=10 {
Expand Down Expand Up @@ -2835,7 +2834,7 @@ mod tests {
// ********** //

#[test]
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
#[expect(clippy::cognitive_complexity, clippy::too_many_lines)]
/// Filter row is drawn correctly & colors are correct
/// Colours change when filter_by option is changed
fn test_draw_blocks_filter_row() {
Expand Down Expand Up @@ -3373,7 +3372,7 @@ mod tests {
}

#[test]
#[allow(clippy::too_many_lines)]
#[expect(clippy::too_many_lines)]
/// Check that the whole layout is drawn correctly
fn test_draw_blocks_whole_layout_with_filter() {
let (w, h) = (160, 30);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/gui_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub enum DeleteButton {
No,
}

#[allow(unused)]
#[expect(unused)]
#[derive(Debug, Clone, Copy)]
pub enum BoxLocation {
TopLeft,
Expand Down

0 comments on commit 2a0ab6d

Please # to comment.