From 047ce32efd2762b127f086b4216a1b96cf8112b8 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Sat, 21 Nov 2020 12:38:43 +0100 Subject: [PATCH] Clippy --- components/library/src/library.rs | 7 ++--- components/library/src/taxonomies/mod.rs | 2 +- components/rendering/src/markdown.rs | 32 ++++++++++------------ components/site/src/lib.rs | 2 +- components/templates/src/global_fns/mod.rs | 2 +- src/cmd/serve.rs | 13 +++------ 6 files changed, 25 insertions(+), 33 deletions(-) diff --git a/components/library/src/library.rs b/components/library/src/library.rs index 3aa7748b..02328ac0 100644 --- a/components/library/src/library.rs +++ b/components/library/src/library.rs @@ -112,7 +112,7 @@ impl Library { subsections // Using the original filename to work for multi-lingual sections .entry(grand_parent.join(§ion.file.filename)) - .or_insert_with(|| vec![]) + .or_insert_with(Vec::new) .push(section.file.path.clone()); } @@ -157,7 +157,7 @@ impl Library { parent_is_transparent = section.meta.transparent; } page.ancestors = - ancestors.get(&parent_section_path).cloned().unwrap_or_else(|| vec![]); + ancestors.get(&parent_section_path).cloned().unwrap_or_else(Vec::new); // Don't forget to push the actual parent page.ancestors.push(*section_key); @@ -201,8 +201,7 @@ impl Library { children.sort_by(|a, b| sections_weight[a].cmp(§ions_weight[b])); section.subsections = children; } - section.ancestors = - ancestors.get(§ion.file.path).cloned().unwrap_or_else(|| vec![]); + section.ancestors = ancestors.get(§ion.file.path).cloned().unwrap_or_else(Vec::new); } } diff --git a/components/library/src/taxonomies/mod.rs b/components/library/src/taxonomies/mod.rs index c048bfef..f71d8d95 100644 --- a/components/library/src/taxonomies/mod.rs +++ b/components/library/src/taxonomies/mod.rs @@ -237,7 +237,7 @@ pub fn find_taxonomies(config: &Config, library: &Library) -> Result Result { - let mut language = None; - match kind { + let language = match kind { CodeBlockKind::Fenced(fence_info) => { let fence_info = fence::FenceSettings::new(fence_info); - language = fence_info.language; + fence_info.language } - _ => {} + _ => None, }; + if !context.config.highlight_code() { if let Some(lang) = language { let html = format!(r#"
"#, lang);
@@ -296,22 +296,20 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result") {
                             has_summary = true;
                             Event::Html(CONTINUE_READING.into())
-                        } else {
-                            if in_html_block && markup.contains("
") { + } else if in_html_block && markup.contains("") { + in_html_block = false; + Event::Html(markup.replacen("", "", 1).into()) + } else if markup.contains("pre data-shortcode") { + in_html_block = true; + let m = markup.replacen("
", "", 1);
+                            if m.contains("
") { in_html_block = false; - Event::Html(markup.replacen("", "", 1).into()) - } else if markup.contains("pre data-shortcode") { - in_html_block = true; - let m = markup.replacen("
", "", 1);
-                                if m.contains("
") { - in_html_block = false; - Event::Html(m.replacen("", "", 1).into()) - } else { - Event::Html(m.into()) - } + Event::Html(m.replacen("", "", 1).into()) } else { - event + Event::Html(m.into()) } + } else { + event } } _ => event, diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 1e0f4540..015ac1c0 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -205,7 +205,7 @@ impl Site { } // skip hidden files and non md files - if !path.is_dir() && (!file_name.ends_with(".md") || file_name.starts_with(".")) { + if !path.is_dir() && (!file_name.ends_with(".md") || file_name.starts_with('.')) { continue; } diff --git a/components/templates/src/global_fns/mod.rs b/components/templates/src/global_fns/mod.rs index 2b3693d4..4ba3459a 100644 --- a/components/templates/src/global_fns/mod.rs +++ b/components/templates/src/global_fns/mod.rs @@ -331,7 +331,7 @@ impl GetTaxonomyUrl { } taxonomies.insert(format!("{}-{}", taxo.kind.name, taxo.kind.lang), items); } - Self { taxonomies, default_lang: default_lang.to_string(), slugify: slugify } + Self { taxonomies, default_lang: default_lang.to_string(), slugify } } } impl TeraFn for GetTaxonomyUrl { diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 899d2570..519ac206 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -238,7 +238,7 @@ pub fn serve( // Stop right there if we can't bind to the address let bind_address: SocketAddrV4 = address.parse().unwrap(); if (TcpListener::bind(&bind_address)).is_err() { - return Err(format!("Cannot start server on address {}.", address))?; + return Err(format!("Cannot start server on address {}.", address).into()); } // An array of (path, bool, bool) where the path should be watched for changes, and the boolean value @@ -442,10 +442,7 @@ pub fn serve( loop { match rx.recv() { Ok(event) => { - let can_do_fast_reload = match event { - Remove(_) => false, - _ => true, - }; + let can_do_fast_reload = !matches!(event, Remove(_)); match event { // Intellij does weird things on edit, chmod is there to count those changes @@ -505,10 +502,8 @@ pub fn serve( site = s; } } - } else { - if let Some(s) = recreate_site() { - site = s; - } + } else if let Some(s) = recreate_site() { + site = s; } } (ChangeKind::Templates, partial_path) => {