Obey 1.67 clippy lints (#313)

This commit is contained in:
tveness 2023-02-07 20:56:41 +00:00 committed by GitHub
commit 76d9d0bbda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 37 deletions

View file

@ -155,7 +155,7 @@ impl Cache {
.get(archive_url)
.send()?
.error_for_status()
.with_context(|| format!("Could not download tldr pages from {}", archive_url))?;
.with_context(|| format!("Could not download tldr pages from {archive_url}"))?;
let mut buf: Vec<u8> = vec![];
let bytes_downloaded = resp.copy_to(&mut buf)?;
debug!("{} bytes downloaded", bytes_downloaded);
@ -248,9 +248,9 @@ impl Cache {
languages: &[String],
custom_pages_dir: Option<&Path>,
) -> Option<PageLookupResult> {
let page_filename = format!("{}.md", name);
let patch_filename = format!("{}.patch", name);
let custom_filename = format!("{}.page", name);
let page_filename = format!("{name}.md");
let patch_filename = format!("{name}.patch");
let custom_filename = format!("{name}.page");
// Determine directory paths
let pages_dir = self.pages_dir();
@ -260,7 +260,7 @@ impl Cache {
if lang == "en" {
String::from("pages")
} else {
format!("pages.{}", lang)
format!("pages.{lang}")
}
})
.collect();

View file

@ -308,7 +308,7 @@ impl Config {
// For backwards compatibility reasons, the cache directory can be
// overridden using an env variable. This is deprecated and will be
// phased out in the future.
eprintln!("Warning: The ${} env variable is deprecated, use the `cache_dir` option in the config file instead.", cache_dir_env_var);
eprintln!("Warning: The ${cache_dir_env_var} env variable is deprecated, use the `cache_dir` option in the config file instead.");
PathWithSource {
path: PathBuf::from(env_var),
source: PathSource::EnvVar,
@ -376,7 +376,7 @@ impl Config {
format!("Failed to read from config file at {:?}", &config_file_path)
})?;
toml::from_str(&contents).with_context(|| {
format!("Failed to parse TOML config file at {:?}", config_file_path)
format!("Failed to parse TOML config file at {config_file_path:?}")
})?
} else {
RawConfig::new()

View file

@ -119,12 +119,9 @@ fn clear_cache(cache: &Cache, quietly: bool, enable_styles: bool) {
if !quietly {
let cache_dir = cache.cache_dir().display();
if cache_dir_found {
eprintln!("Successfully cleared cache at `{}`.", cache_dir);
eprintln!("Successfully cleared cache at `{cache_dir}`.");
} else {
eprintln!(
"Cache directory not found at `{}`, nothing to do.",
cache_dir
);
eprintln!("Cache directory not found at `{cache_dir}`, nothing to do.");
}
}
}
@ -143,17 +140,17 @@ fn update_cache(cache: &Cache, quietly: bool, enable_styles: bool) {
/// Show file paths
fn show_paths(config: &Config) {
let config_dir = get_config_dir().map_or_else(
|e| format!("[Error: {}]", e),
|e| format!("[Error: {e}]"),
|(mut path, source)| {
path.push(""); // Trailing path separator
match path.to_str() {
Some(path) => format!("{} ({})", path, source),
Some(path) => format!("{path} ({source})"),
None => "[Invalid]".to_string(),
}
},
);
let config_path = get_config_path().map_or_else(
|e| format!("[Error: {}]", e),
|e| format!("[Error: {e}]"),
|(path, _)| path.display().to_string(),
);
let cache_dir = config.directories.cache_dir.to_string();
@ -167,11 +164,11 @@ fn show_paths(config: &Config) {
Some(ref path_with_source) => path_with_source.to_string(),
None => "[None]".to_string(),
};
println!("Config dir: {}", config_dir);
println!("Config path: {}", config_path);
println!("Cache dir: {}", cache_dir);
println!("Pages dir: {}", pages_dir);
println!("Custom pages dir: {}", custom_pages_dir);
println!("Config dir: {config_dir}");
println!("Config path: {config_path}");
println!("Cache dir: {cache_dir}");
println!("Pages dir: {pages_dir}");
println!("Custom pages dir: {custom_pages_dir}");
}
/// Create seed config file and exit

View file

@ -51,7 +51,7 @@ pub fn print_page(
// Print the raw markdown of the file.
for line in reader.lines() {
let line = line.context("Error while reading from a page")?;
writeln!(handle, "{}", line).context("Could not write to stdout")?;
writeln!(handle, "{line}").context("Could not write to stdout")?;
}
} else {
// Closure that processes a page snippet and writes it to stdout

View file

@ -9,18 +9,13 @@ pub fn print_warning(enable_styles: bool, message: &str) {
/// Print an anyhow error to stderr. If `enable_styles` is true, then a red
/// message will be printed.
pub fn print_error(enable_styles: bool, error: &anyhow::Error) {
print_msg(
enable_styles,
&format!("{:?}", error),
"Error: ",
Color::Red,
);
print_msg(enable_styles, &format!("{error:?}"), "Error: ", Color::Red);
}
fn print_msg(enable_styles: bool, message: &str, prefix: &'static str, color: Color) {
if enable_styles {
eprintln!("{}{}", color.paint(prefix), color.paint(message));
} else {
eprintln!("{}", message);
eprintln!("{message}");
}
}

View file

@ -55,7 +55,7 @@ impl TestEnv {
/// Write `content` to "config.toml" in the `config_dir` directory
fn write_config(&self, content: impl AsRef<str>) {
let config_file_name = self.config_dir.path().join("config.toml");
println!("Config path: {:?}", config_file_name);
println!("Config path: {config_file_name:?}");
let mut config_file = File::create(&config_file_name).unwrap();
config_file.write_all(content.as_ref().as_bytes()).unwrap();
@ -76,7 +76,7 @@ impl TestEnv {
.join(os);
create_dir_all(&dir).unwrap();
let mut file = File::create(&dir.join(format!("{}.md", name))).unwrap();
let mut file = File::create(dir.join(format!("{name}.md"))).unwrap();
file.write_all(contents.as_bytes()).unwrap();
}
@ -84,7 +84,7 @@ impl TestEnv {
fn add_page_entry(&self, name: &str, contents: &str) {
let dir = self.custom_pages_dir.path();
create_dir_all(dir).unwrap();
let mut file = File::create(&dir.join(format!("{}.page", name))).unwrap();
let mut file = File::create(dir.join(format!("{name}.page"))).unwrap();
file.write_all(contents.as_bytes()).unwrap();
}
@ -92,7 +92,7 @@ impl TestEnv {
fn add_patch_entry(&self, name: &str, contents: &str) {
let dir = self.custom_pages_dir.path();
create_dir_all(dir).unwrap();
let mut file = File::create(&dir.join(format!("{}.patch", name))).unwrap();
let mut file = File::create(dir.join(format!("{name}.patch"))).unwrap();
file.write_all(contents.as_bytes()).unwrap();
}
@ -120,7 +120,7 @@ impl TestEnv {
build = build.arg("--no-default-features");
}
if !self.features.is_empty() {
build = build.arg(&format!("--feature {}", self.features.join(",")));
build = build.arg(format!("--feature {}", self.features.join(",")));
}
let run = build.run().unwrap();
let mut cmd = run.command();
@ -426,7 +426,7 @@ fn _test_correct_rendering(
// Create input file
let file_path = testenv.input_dir.path().join(filename);
println!("Testfile path: {:?}", file_path);
println!("Testfile path: {file_path:?}");
let mut file = File::create(&file_path).unwrap();
file.write_all(input_file.as_bytes()).unwrap();
@ -501,7 +501,7 @@ fn test_correct_rendering_with_config() {
// Setup config file
// TODO should be config::CONFIG_FILE_NAME
let config_file_path = testenv.config_dir.path().join("config.toml");
println!("Config path: {:?}", config_file_path);
println!("Config path: {config_file_path:?}");
let mut config_file = File::create(&config_file_path).unwrap();
config_file
@ -510,7 +510,7 @@ fn test_correct_rendering_with_config() {
// Create input file
let file_path = testenv.input_dir.path().join("inkscape-v2.md");
println!("Testfile path: {:?}", file_path);
println!("Testfile path: {file_path:?}");
let mut file = File::create(&file_path).unwrap();
file.write_all(include_bytes!("inkscape-v2.md")).unwrap();
@ -620,7 +620,7 @@ fn test_autoupdate_cache() {
let cache_file_path = testenv.cache_dir.path().join(TLDR_PAGES_DIR);
// Activate automatic updates, set the auto-update interval to 24 hours
let mut config_file = File::create(&config_file_path).unwrap();
let mut config_file = File::create(config_file_path).unwrap();
config_file
.write_all(b"[updates]\nauto_update = true\nauto_update_interval_hours = 24")
.unwrap();