updated formatting options

This commit is contained in:
Lynne Megido 2021-11-06 01:30:34 +10:00
parent 855211f458
commit 28aa3ad783
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
5 changed files with 14 additions and 56 deletions

View File

@ -7,3 +7,5 @@ hard_tabs = true
tab_spaces = 2
newline_style = "Unix"
group_imports = "StdExternalCrate"
array_width = 100
fn_call_width = 80

View File

@ -209,11 +209,7 @@ pub fn scan_directory(
// TODO: is there a way to just say `map_or(x, |y| y).thing()` instead of `map_or(x.thing(), |y| y.thing())`?
// i don't care whether i'm returning a walkdir error or an io error, i just care about whether or not it
// implements ToString (which they both do). map_or doesn't work on trait objects though :(
error!(
"{}: {}",
path,
err.io_error().map_or(err.to_string(), |e| e.to_string())
);
error!("{}: {}", path, err.io_error().map_or(err.to_string(), |e| e.to_string()));
return None;
}
e.ok()
@ -353,23 +349,14 @@ pub fn mime_extension_lookup(essence: String) -> Option<Vec<String>> {
} else if essence == "application/zip" {
// neither xdg-mime nor infer seem to be able to detect office XML files properly...
[
vec![
String::from("zip"),
String::from("docx"),
String::from("xlsx"),
String::from("pptx"),
],
vec![String::from("zip"), String::from("docx"), String::from("xlsx"), String::from("pptx")],
possible_exts,
]
.concat()
} else if essence == "application/x-ms-dos-executable" {
// .dll, .exe, and .scr files are given the same mime type... but you definitely don't want to rename one to the
// other!
[
vec![String::from("dll"), String::from("exe"), String::from("scr")],
possible_exts,
]
.concat()
[vec![String::from("dll"), String::from("exe"), String::from("scr")], possible_exts].concat()
} else {
possible_exts
})
@ -381,6 +368,8 @@ pub fn mime_extension_lookup(essence: String) -> Option<Vec<String>> {
cache.insert(essence, exts.clone());
exts
} else {
// this should only ever happen if cache.insert() hangs on another thread; i.e., close enough to "never" that
// marking this as unreachable should be fine
unreachable!()
}
}

View File

@ -179,14 +179,7 @@ impl FormatSteps for Shell {
fn no_known_extension<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
smart_write(
f,
writablesln![
"cat <<- '???'",
Newline,
"No known extension for ",
path,
Newline,
"???"
],
writablesln!["cat <<- '???'", Newline, "No known extension for ", path, Newline, "???"],
)
}
@ -199,10 +192,7 @@ impl FormatSteps for Shell {
}
fn header<W: Write>(&self, f: &mut W) -> io::Result<()> {
smart_write(
f,
writablesln!["#!/usr/bin/env sh", Newline, "# ", (generated_by().as_str())],
)?;
smart_write(f, writablesln!["#!/usr/bin/env sh", Newline, "# ", (generated_by().as_str())])?;
if let Ok(working_directory) = std::env::current_dir() {
smart_write(f, writablesln!["# Run from ", (working_directory.as_path())])?;
@ -232,26 +222,14 @@ impl FormatSteps for PowerShell {
// there doesn't seem to be a way to rename the file, prompting only if the target already exists.
smart_write(
f,
writablesln![
"Rename-Item -Verbose -Path ",
from,
" -NewName ",
(to.file_name().unwrap())
],
writablesln!["Rename-Item -Verbose -Path ", from, " -NewName ", (to.file_name().unwrap())],
)
}
fn no_known_extension<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
smart_write(
f,
writablesln![
"Write-Output @'",
Newline,
"No known extension for ",
path,
Newline,
"'@"
],
writablesln!["Write-Output @'", Newline, "No known extension for ", path, Newline, "'@"],
)
}

View File

@ -319,12 +319,7 @@ impl ExtensionSet {
Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(),
Self::Audio => mime_guess::get_mime_extensions_str("audio/*").unwrap().to_vec(),
Self::Video => mime_guess::get_mime_extensions_str("video/*").unwrap().to_vec(),
Self::Media => [
Self::Images.extensions(),
Self::Audio.extensions(),
Self::Video.extensions(),
]
.concat(),
Self::Media => [Self::Images.extensions(), Self::Audio.extensions(), Self::Video.extensions()].concat(),
Self::Documents => vec![
"pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "odt", "ods", "odp", "oda", "rtf", "ps",
"pages", "key", "numbers",

View File

@ -141,10 +141,7 @@ fn simple_directory() {
// 3. ensure the recommended extension for "wrong.jpg" is "png"
assert_eq!(&result.recommended_extension().unwrap(), &String::from("png"));
// 4. ensure the recommended filename for "wrong.jpg" is "wrong.png"
assert_eq!(
result.recommended_path().unwrap().file_name(),
Some(OsStr::new("wrong.png"))
);
assert_eq!(result.recommended_path().unwrap().file_name(), Some(OsStr::new("wrong.png")));
continue;
}
@ -470,10 +467,7 @@ fn verbosity() {
#[test]
/// Ensures `os_name()`'s output is the same as [`std::env::consts::OS`], capitalisation notwithstanding
fn validate_os_name() {
assert_eq!(
fif::utils::os_name().to_lowercase(),
std::env::consts::OS.to_lowercase()
);
assert_eq!(fif::utils::os_name().to_lowercase(), std::env::consts::OS.to_lowercase());
}
#[test]