From f16d88eb68023b6212f350afabf0cf73991b4577 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Fri, 29 Nov 2024 19:23:24 -0500 Subject: [PATCH] chore: apply clippy lint suggestions warning: this argument is passed by value, but not consumed in the function body --> src/cmd/template.rs:539:24 | 539 | fn format_float(value: Value, precision: u32) -> String { | ^^^^^ help: consider taking a reference instead: `&Value` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value = note: `-W clippy::needless-pass-by-value` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::needless_pass_by_value)]` warning: variables can be used directly in the `format!` string --> src/cmd/template.rs:547:17 | 547 | format!("{:.1$}", float_num, precision) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args = note: `-W clippy::uninlined-format-args` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::uninlined_format_args)]` help: change this to | 547 - format!("{:.1$}", float_num, precision) 547 + format!("{float_num:.precision$}") | warning: variables can be used directly in the `format!` string --> src/cmd/template.rs:559:27 | 559 | |num| format!("{:.1$}", num, precision), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 559 - |num| format!("{:.1$}", num, precision), 559 + |num| format!("{num:.precision$}"), | --- src/cmd/template.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/template.rs b/src/cmd/template.rs index 329a0e5ab..c965f7955 100644 --- a/src/cmd/template.rs +++ b/src/cmd/template.rs @@ -536,7 +536,7 @@ fn substr(value: &str, start: u32, end: Option) -> String { /// Formats a float number string with the specified decimal precision. /// Returns --customfilter-error (default: ) if input cannot be parsed as float. -fn format_float(value: Value, precision: u32) -> String { +fn format_float(value: &Value, precision: u32) -> String { // Prevent excessive precision let precision = precision.min(16) as usize; match value.kind() { @@ -544,7 +544,7 @@ fn format_float(value: Value, precision: u32) -> String { let float_num: f64; if let Ok(num) = value.clone().try_into() { float_num = num; - format!("{:.1$}", float_num, precision) + format!("{float_num:.precision$}") } else { format!( r#"{}: "{value}" is not a float."#, @@ -556,7 +556,7 @@ fn format_float(value: Value, precision: u32) -> String { if let Some(s) = value.as_str() { s.parse::().map_or_else( |_| FILTER_ERROR.get().unwrap().clone(), - |num| format!("{:.1$}", num, precision), + |num| format!("{num:.precision$}"), ) } else { format!(