Skip to content

Commit

Permalink
chore: apply clippy lint suggestions
Browse files Browse the repository at this point in the history
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$}"),
    |
  • Loading branch information
jqnatividad committed Nov 30, 2024
1 parent d38d1b7 commit f16d88e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cmd/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,15 @@ fn substr(value: &str, start: u32, end: Option<u32>) -> String {

/// Formats a float number string with the specified decimal precision.
/// Returns --customfilter-error (default: <FILTER_ERROR>) 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() {
ValueKind::Number => {
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."#,
Expand All @@ -556,7 +556,7 @@ fn format_float(value: Value, precision: u32) -> String {
if let Some(s) = value.as_str() {
s.parse::<f64>().map_or_else(
|_| FILTER_ERROR.get().unwrap().clone(),
|num| format!("{:.1$}", num, precision),
|num| format!("{num:.precision$}"),
)
} else {
format!(
Expand Down

0 comments on commit f16d88e

Please sign in to comment.