mirror of
https://github.com/nushell/nushell.git
synced 2025-08-15 16:03:17 +02:00
Use variable names directly in the format strings (#7906)
# Description Lint: `clippy::uninlined_format_args` More readable in most situations. (May be slightly confusing for modifier format strings https://doc.rust-lang.org/std/fmt/index.html#formatting-parameters) Alternative to #7865 # User-Facing Changes None intended # Tests + Formatting (Ran `cargo +stable clippy --fix --workspace -- -A clippy::all -D clippy::uninlined_format_args` to achieve this. Depends on Rust `1.67`)
This commit is contained in:
committed by
GitHub
parent
6ae497eedc
commit
ab480856a5
@ -160,7 +160,7 @@ fn create_default_value() -> Value {
|
||||
|
||||
let record = |i: usize| Value::Record {
|
||||
cols: vec![String::from("key"), String::from("value")],
|
||||
vals: vec![nu_str(format!("key-{}", i)), nu_str(format!("{}", i))],
|
||||
vals: vec![nu_str(format!("key-{i}")), nu_str(format!("{i}"))],
|
||||
span,
|
||||
};
|
||||
|
||||
|
@ -176,6 +176,6 @@ pub fn default_color_list() -> Vec<HelpExample> {
|
||||
|
||||
pub fn default_int_list() -> Vec<HelpExample> {
|
||||
(0..20)
|
||||
.map(|i| HelpExample::new(i.to_string(), format!("A value equal to {}", i)))
|
||||
.map(|i| HelpExample::new(i.to_string(), format!("A value equal to {i}")))
|
||||
.collect()
|
||||
}
|
||||
|
@ -882,7 +882,7 @@ fn convert_with_precision(val: &str, precision: usize) -> Result<String, ShellEr
|
||||
));
|
||||
}
|
||||
};
|
||||
Ok(format!("{:.prec$}", val_float, prec = precision))
|
||||
Ok(format!("{val_float:.precision$}"))
|
||||
}
|
||||
|
||||
fn load_theme_from_config(config: &Config) -> TableTheme {
|
||||
|
@ -393,10 +393,9 @@ fn handle_command(
|
||||
run_command(engine_state, stack, pager, view, view_stack, command, args)
|
||||
}
|
||||
Some(Err(err)) => Err(format!(
|
||||
"Error: command {:?} was not provided with correct arguments: {}",
|
||||
args, err
|
||||
"Error: command {args:?} was not provided with correct arguments: {err}"
|
||||
)),
|
||||
None => Err(format!("Error: command {:?} was not recognized", args)),
|
||||
None => Err(format!("Error: command {args:?} was not recognized")),
|
||||
}
|
||||
}
|
||||
|
||||
@ -447,7 +446,7 @@ fn run_command(
|
||||
Transition::Exit => Ok(true),
|
||||
Transition::Cmd { .. } => todo!("not used so far"),
|
||||
},
|
||||
Err(err) => Err(format!("Error: command {:?} failed: {}", args, err)),
|
||||
Err(err) => Err(format!("Error: command {args:?} failed: {err}")),
|
||||
}
|
||||
}
|
||||
Command::View { mut cmd, is_light } => {
|
||||
@ -472,7 +471,7 @@ fn run_command(
|
||||
*view = Some(Page::raw(new_view, is_light));
|
||||
Ok(false)
|
||||
}
|
||||
Err(err) => Err(format!("Error: command {:?} failed: {}", args, err)),
|
||||
Err(err) => Err(format!("Error: command {args:?} failed: {err}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -581,7 +580,7 @@ fn render_cmd_bar_search(f: &mut Frame, area: Rect, pager: &Pager<'_>, theme: &S
|
||||
} else {
|
||||
let index = pager.search_buf.search_index + 1;
|
||||
let total = pager.search_buf.search_results.len();
|
||||
format!("[{}/{}]", index, total)
|
||||
format!("[{index}/{total}]")
|
||||
};
|
||||
|
||||
let bar = CommandBar::new(&text, &info, theme.cmd_bar_text, theme.cmd_bar_background);
|
||||
@ -604,7 +603,7 @@ fn render_cmd_bar_cmd(f: &mut Frame, area: Rect, pager: &Pager, theme: &StyleCon
|
||||
}
|
||||
|
||||
let prefix = ':';
|
||||
let text = format!("{}{}", prefix, input);
|
||||
let text = format!("{prefix}{input}");
|
||||
|
||||
let bar = CommandBar::new(&text, "", theme.cmd_bar_text, theme.cmd_bar_background);
|
||||
f.render_widget(bar, area);
|
||||
|
@ -195,9 +195,7 @@ impl View for InteractiveView<'_> {
|
||||
if self.immediate {
|
||||
match self.try_run(engine_state, stack) {
|
||||
Ok(_) => info.report = Some(Report::default()),
|
||||
Err(err) => {
|
||||
info.report = Some(Report::error(format!("Error: {}", err)))
|
||||
}
|
||||
Err(err) => info.report = Some(Report::error(format!("Error: {err}"))),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -210,7 +208,7 @@ impl View for InteractiveView<'_> {
|
||||
if self.immediate {
|
||||
match self.try_run(engine_state, stack) {
|
||||
Ok(_) => info.report = Some(Report::default()),
|
||||
Err(err) => info.report = Some(Report::error(format!("Error: {}", err))),
|
||||
Err(err) => info.report = Some(Report::error(format!("Error: {err}"))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,7 +224,7 @@ impl View for InteractiveView<'_> {
|
||||
KeyCode::Enter => {
|
||||
match self.try_run(engine_state, stack) {
|
||||
Ok(_) => info.report = Some(Report::default()),
|
||||
Err(err) => info.report = Some(Report::error(format!("Error: {}", err))),
|
||||
Err(err) => info.report = Some(Report::error(format!("Error: {err}"))),
|
||||
}
|
||||
|
||||
Some(Transition::Ok)
|
||||
|
@ -691,11 +691,11 @@ fn report_cursor_position(mode: UIMode, cursor: XYCursor) -> String {
|
||||
if mode == UIMode::Cursor {
|
||||
let row = cursor.row();
|
||||
let column = cursor.column();
|
||||
format!("{},{}", row, column)
|
||||
format!("{row},{column}")
|
||||
} else {
|
||||
let rows_seen = cursor.row_starts_at();
|
||||
let columns_seen = cursor.column_starts_at();
|
||||
format!("{},{}", rows_seen, columns_seen)
|
||||
format!("{rows_seen},{columns_seen}")
|
||||
}
|
||||
}
|
||||
|
||||
@ -707,13 +707,13 @@ fn report_row_position(cursor: XYCursor) -> String {
|
||||
|
||||
match percent_rows {
|
||||
100 => String::from("All"),
|
||||
value => format!("{}%", value),
|
||||
value => format!("{value}%"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_percentage(value: usize, max: usize) -> usize {
|
||||
debug_assert!(value <= max, "{:?} {:?}", value, max);
|
||||
debug_assert!(value <= max, "{value:?} {max:?}");
|
||||
|
||||
((value as f32 / max as f32) * 100.0).floor() as usize
|
||||
}
|
||||
|
@ -161,5 +161,5 @@ fn convert_with_precision(val: &str, precision: usize) -> Result<String, ShellEr
|
||||
));
|
||||
}
|
||||
};
|
||||
Ok(format!("{:.prec$}", val_float, prec = precision))
|
||||
Ok(format!("{val_float:.precision$}"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user