clippy, format

This commit is contained in:
Lynne Megido 2023-03-15 06:51:29 +10:00
parent 4469104ac1
commit 5017854dd3
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
5 changed files with 17 additions and 22 deletions

View file

@ -90,7 +90,7 @@ pub fn smart_write<W: Write>(f: &mut W, writeables: &[Writable]) -> io::Result<(
}
}
}
Writable::String(s) => write!(f, "{}", s)?,
Writable::String(s) => write!(f, "{s}")?,
Writable::Path(path) => {
if let Some(path_str) = path.to_str() {
let escaped = escape(path_str);
@ -98,9 +98,9 @@ pub fn smart_write<W: Write>(f: &mut W, writeables: &[Writable]) -> io::Result<(
// the escaped string is the same as the input - this will occur for inputs like "file.txt" which don't
// need to be escaped. however, it's Best Practice™ to escape such strings anyway, so we prefix/suffix the
// escaped string with single quotes.
write!(f, "'{}'", escaped)?;
write!(f, "'{escaped}'")?;
} else {
write!(f, "{}", escaped)?;
write!(f, "{escaped}")?;
}
} else {
write!(f, "'")?;

View file

@ -132,7 +132,7 @@ fn main() {
if args.fix {
fn ask(message: &str) -> bool {
let mut buf = String::with_capacity(1);
print!("{} [y/N] ", message);
print!("{message} [y/N] ");
// flush stdout to ensure message is displayed
stdout().flush().expect("Failed to flush stdout");
@ -166,7 +166,7 @@ fn main() {
} else if prompt == Prompt::Error || ask(&format!("Rename {:#?} to {:#?}?", &f.file, &rename_to)) {
// handles: --prompt error --overwrite, --prompt always --overwrite [y]
// if the target exists, prompt before renaming; otherwise, just rename
!rename_to.exists() || ask(&format!("Destination {:#?} already exists, overwrite?", rename_to))
!rename_to.exists() || ask(&format!("Destination {rename_to:#?} already exists, overwrite?"))
} else {
// handles: --prompt always --overwrite [n]
// user was prompted and replied "no"
@ -191,7 +191,7 @@ fn main() {
warn!("Couldn't rename {:#?} to {:#?}: {:#?}", f.file, rename_to, e);
// if the user passed --prompt never, continue to the next file
// otherwise, prompt user to retry move, retrying until the rename succeeds or they respond "N"
if prompt == Prompt::Never || !ask(&format!("Error while renaming file: {:#?}. Try again?", e)) {
if prompt == Prompt::Never || !ask(&format!("Error while renaming file: {e:#?}. Try again?")) {
failed += 1;
break;
}

View file

@ -32,7 +32,7 @@ cfg_if! {
}
fn open_document_check(buf: &[u8], kind: &str) -> bool {
let mime = format!("application/vnd.oasis.opendocument.{}", kind);
let mime = format!("application/vnd.oasis.opendocument.{kind}");
let mime = mime.as_bytes();
buf.len() > 38 + mime.len() && buf.starts_with(b"PK\x03\x04") && buf[38..mime.len() + 38] == mime[..]

View file

@ -7,7 +7,7 @@ use std::collections::BTreeSet;
use std::path::PathBuf;
use cfg_if::cfg_if;
use clap::{ValueEnum, Parser, ArgAction};
use clap::{ArgAction, Parser, ValueEnum};
use crate::utils::{CLAP_LONG_VERSION, CLAP_VERSION};
use crate::String as StringType;

View file

@ -102,12 +102,11 @@ fn simple_directory() {
set_current_dir(dir.path()).expect("Failed to change directory.");
for (name, bytes) in &files {
let mut file = File::create(dir.path().join(name))
.unwrap_or_else(|_| panic!("Failed to create file: {}", name));
let mut file = File::create(dir.path().join(name)).unwrap_or_else(|_| panic!("Failed to create file: {name}"));
file
.write_all(bytes)
.unwrap_or_else(|_| panic!("Failed to write to file: {}", name));
.unwrap_or_else(|_| panic!("Failed to write to file: {name}"));
drop(file);
}
@ -280,12 +279,12 @@ fn exclude_set_overrides_include_set() {
.iter()
.chain(ExtensionSet::Video.extensions().iter())
{
assert!(extensions.contains(&ext), "Extensions should contain {}!", ext);
assert!(extensions.contains(&ext), "Extensions should contain {ext}!");
}
// ensure all of images' extensions are excluded
for ext in ExtensionSet::Images.extensions() {
assert!(!extensions.contains(&ext), "Extensions should not contain {}!", ext);
assert!(!extensions.contains(&ext), "Extensions should not contain {ext}!");
}
}
@ -316,7 +315,7 @@ fn rejects_bad_args() {
for test in &tests {
// first, try testing the flags against the Parameters struct...
assert!(Parameters::try_parse_from(test).is_err(), "Failed to reject {:?}", test);
assert!(Parameters::try_parse_from(test).is_err(), "Failed to reject {test:?}");
// ...then, make sure it actually works against the binary
let mut cmd = Command::cargo_bin("fif").unwrap();
cmd.args(test).assert().failure();
@ -359,8 +358,7 @@ fn check_version_output() {
let output = String::from_utf8(output).unwrap();
assert!(
Regex::new(r#"fif v([0-9]\.){2}[0-9]"#).unwrap().is_match(output.trim()),
"\"{}\" does not match the expected `-v` format!",
output
"\"{output}\" does not match the expected `-v` format!"
);
// test `--version` matches the format of "fif x.y.z (OS, example backend, commit #1234abc)"
@ -393,7 +391,7 @@ fn identify_random_bytes() {
}
for (mime, count) in &results {
println!("{}:\t{} counts", mime, count);
println!("{mime}:\t{count} counts");
}
println!("No type found:\t{} counts", 1000 - results.values().sum::<i32>());
}
@ -430,9 +428,7 @@ fn outputs_move_commands() {
// the output should contain a command like "mv -i misnamed_file.png misnamed_file.jpg"
assert!(
contents.contains("misnamed_file.jpg") && contents.contains("misnamed_file.png"),
"{} output doesn't contain move command!\n===\n{}",
format,
contents
"{format} output doesn't contain move command!\n===\n{contents}"
);
}
}
@ -466,8 +462,7 @@ fn test_json() {
// the output should contain the file's MIME type
assert!(
contents.contains(IMAGE_JPEG.essence_str()),
"JSON output doesn't contain move command!\n===\n{}",
contents
"JSON output doesn't contain move command!\n===\n{contents}"
);
}