mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 16:05:01 +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
@ -157,7 +157,7 @@ pub(crate) fn parse_commandline_args(
|
||||
if call.has_flag("version") {
|
||||
let version = env!("CARGO_PKG_VERSION").to_string();
|
||||
let _ = std::panic::catch_unwind(move || {
|
||||
stdout_write_all_and_flush(format!("{}\n", version))
|
||||
stdout_write_all_and_flush(format!("{version}\n"))
|
||||
});
|
||||
|
||||
std::process::exit(0);
|
||||
@ -190,7 +190,7 @@ pub(crate) fn parse_commandline_args(
|
||||
&mut stack,
|
||||
true,
|
||||
);
|
||||
print!("{}", full_help);
|
||||
print!("{full_help}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ pub(crate) fn read_config_file(
|
||||
// Create config directory if it does not exist
|
||||
if !config_path.exists() {
|
||||
if let Err(err) = std::fs::create_dir_all(&config_path) {
|
||||
eprintln!("Failed to create config directory: {}", err);
|
||||
eprintln!("Failed to create config directory: {err}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,7 @@ pub(crate) fn read_config_file(
|
||||
match answer.to_lowercase().trim() {
|
||||
"y" | "" => {
|
||||
if let Ok(mut output) = File::create(&config_path) {
|
||||
if write!(output, "{}", config_file).is_ok() {
|
||||
if write!(output, "{config_file}").is_ok() {
|
||||
let config_type = if is_env_config {
|
||||
"Environment config"
|
||||
} else {
|
||||
@ -93,10 +93,7 @@ pub(crate) fn read_config_file(
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
eprintln!(
|
||||
"Unable to create {}, sourcing default file instead",
|
||||
config_file
|
||||
);
|
||||
eprintln!("Unable to create {config_file}, sourcing default file instead");
|
||||
eval_default_config(engine_state, stack, config_file, is_env_config);
|
||||
return;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ pub fn logger(
|
||||
LogTarget::File => {
|
||||
let pid = std::process::id();
|
||||
let mut path = std::env::temp_dir();
|
||||
path.push(format!("nu-{}.log", pid));
|
||||
path.push(format!("nu-{pid}.log"));
|
||||
|
||||
set_write_logger(level, config, &path)
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ pub fn echo_env(to_stdout: bool) {
|
||||
for arg in args {
|
||||
if let Ok(v) = std::env::var(arg) {
|
||||
if to_stdout {
|
||||
println!("{}", v);
|
||||
println!("{v}");
|
||||
} else {
|
||||
eprintln!("{}", v);
|
||||
eprintln!("{v}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -42,7 +42,7 @@ pub fn meow() {
|
||||
|
||||
for arg in args.iter().skip(1) {
|
||||
let contents = std::fs::read_to_string(arg).expect("Expected a filepath");
|
||||
println!("{}", contents);
|
||||
println!("{contents}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ pub fn relay() {
|
||||
}
|
||||
|
||||
pub fn nonu() {
|
||||
args().iter().skip(1).for_each(|arg| print!("{}", arg));
|
||||
args().iter().skip(1).for_each(|arg| print!("{arg}"));
|
||||
}
|
||||
|
||||
pub fn repeater() {
|
||||
@ -79,7 +79,7 @@ pub fn repeater() {
|
||||
let count: u64 = count.parse().expect("can't convert count to number");
|
||||
|
||||
for _ in 0..count {
|
||||
let _ = write!(stdout, "{}", letter);
|
||||
let _ = write!(stdout, "{letter}");
|
||||
}
|
||||
let _ = stdout.flush();
|
||||
}
|
||||
@ -91,7 +91,7 @@ pub fn iecho() {
|
||||
.iter()
|
||||
.skip(1)
|
||||
.cycle()
|
||||
.try_for_each(|v| writeln!(stdout, "{}", v));
|
||||
.try_for_each(|v| writeln!(stdout, "{v}"));
|
||||
}
|
||||
|
||||
pub fn fail() {
|
||||
@ -116,7 +116,7 @@ pub fn chop() {
|
||||
&given[..to]
|
||||
};
|
||||
|
||||
if let Err(_e) = writeln!(stdout, "{}", chopped) {
|
||||
if let Err(_e) = writeln!(stdout, "{chopped}") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -136,7 +136,7 @@ fn outcome_err(
|
||||
}
|
||||
|
||||
fn outcome_ok(msg: String) -> ! {
|
||||
println!("{}", msg);
|
||||
println!("{msg}");
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
@ -194,7 +194,7 @@ pub fn nu_repl() {
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
let (block, err) = parse(
|
||||
&mut working_set,
|
||||
Some(&format!("line{}", i)),
|
||||
Some(&format!("line{i}")),
|
||||
line.as_bytes(),
|
||||
false,
|
||||
&[],
|
||||
@ -248,7 +248,7 @@ fn did_chop_arguments() -> bool {
|
||||
&arg[..to]
|
||||
};
|
||||
|
||||
println!("{}", chopped);
|
||||
println!("{chopped}");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
20
src/tests.rs
20
src/tests.rs
@ -34,7 +34,7 @@ pub fn run_test_with_env(input: &str, expected: &str, env: &HashMap<&str, &str>)
|
||||
let mut cmd = Command::cargo_bin("nu")?;
|
||||
cmd.arg(name).envs(env);
|
||||
|
||||
writeln!(file, "{}", input)?;
|
||||
writeln!(file, "{input}")?;
|
||||
|
||||
run_cmd_and_assert(cmd, expected)
|
||||
}
|
||||
@ -51,7 +51,7 @@ pub fn run_test(input: &str, expected: &str) -> TestResult {
|
||||
std::env::current_dir().expect("Can't get current dir"),
|
||||
);
|
||||
|
||||
writeln!(file, "{}", input)?;
|
||||
writeln!(file, "{input}")?;
|
||||
|
||||
run_cmd_and_assert(cmd, expected)
|
||||
}
|
||||
@ -63,8 +63,8 @@ fn run_cmd_and_assert(mut cmd: Command, expected: &str) -> TestResult {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
|
||||
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
|
||||
println!("stdout: {}", stdout);
|
||||
println!("stderr: {}", stderr);
|
||||
println!("stdout: {stdout}");
|
||||
println!("stderr: {stderr}");
|
||||
|
||||
assert!(output.status.success());
|
||||
|
||||
@ -81,15 +81,15 @@ pub fn run_test_contains(input: &str, expected: &str) -> TestResult {
|
||||
let mut cmd = Command::cargo_bin("nu")?;
|
||||
cmd.arg(name);
|
||||
|
||||
writeln!(file, "{}", input)?;
|
||||
writeln!(file, "{input}")?;
|
||||
|
||||
let output = cmd.output()?;
|
||||
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
|
||||
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
|
||||
println!("stdout: {}", stdout);
|
||||
println!("stderr: {}", stderr);
|
||||
println!("stdout: {stdout}");
|
||||
println!("stderr: {stderr}");
|
||||
|
||||
assert!(output.status.success());
|
||||
|
||||
@ -110,15 +110,15 @@ pub fn fail_test(input: &str, expected: &str) -> TestResult {
|
||||
std::env::current_dir().expect("Can't get current dir"),
|
||||
);
|
||||
|
||||
writeln!(file, "{}", input)?;
|
||||
writeln!(file, "{input}")?;
|
||||
|
||||
let output = cmd.output()?;
|
||||
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
|
||||
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
|
||||
println!("stdout: {}", stdout);
|
||||
println!("stderr: {}", stderr);
|
||||
println!("stdout: {stdout}");
|
||||
println!("stderr: {stderr}");
|
||||
|
||||
assert!(!stderr.is_empty() && stderr.contains(expected));
|
||||
|
||||
|
@ -25,14 +25,14 @@ fn test_alternate_config_path() {
|
||||
nu_path::canonicalize_with(config_file, &cwd).expect("Could not get config path");
|
||||
let actual = nu!(
|
||||
cwd: &cwd,
|
||||
format!("nu --config {:?} -c '$nu.config-path'", config_path)
|
||||
format!("nu --config {config_path:?} -c '$nu.config-path'")
|
||||
);
|
||||
assert_eq!(actual.out, config_path.to_string_lossy().to_string());
|
||||
|
||||
let env_path = nu_path::canonicalize_with(env_file, &cwd).expect("Could not get env path");
|
||||
let actual = nu!(
|
||||
cwd: &cwd,
|
||||
format!("nu --env-config {:?} -c '$nu.env-path'", env_path)
|
||||
format!("nu --env-config {env_path:?} -c '$nu.env-path'")
|
||||
);
|
||||
assert_eq!(actual.out, env_path.to_string_lossy().to_string());
|
||||
}
|
||||
|
Reference in New Issue
Block a user