From dadb69a14b7012b5ed704bcd9356649493879deb Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 17 Mar 2022 21:03:06 +1000 Subject: [PATCH] Fix some clippy lints + imports --- rslib/i18n/build/gather.rs | 10 ++++++---- rslib/i18n/build/write_strings.rs | 7 ++++--- rslib/src/card_rendering/writer.rs | 2 +- rslib/src/notetype/mod.rs | 2 +- rslib/src/notetype/render.rs | 3 +-- rslib/src/search/writer.rs | 12 ++++++------ rslib/src/tags/rename.rs | 3 +-- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/rslib/i18n/build/gather.rs b/rslib/i18n/build/gather.rs index ebf33b9bf..3e1350aa2 100644 --- a/rslib/i18n/build/gather.rs +++ b/rslib/i18n/build/gather.rs @@ -10,9 +10,11 @@ //! repo. If it is pointed at a different location, the Qt translations will be excluded //! and the provided translations embedded instead. -use std::path::Path; -use std::{collections::HashMap, env}; -use std::{fs, path::PathBuf}; +use std::{ + collections::HashMap, + env, fs, + path::{Path, PathBuf}, +}; pub type TranslationsByFile = HashMap; pub type TranslationsByLang = HashMap; @@ -51,7 +53,7 @@ fn add_folder(map: &mut TranslationsByLang, folder: &Path, lang: &str) { if !fname.ends_with(".ftl") { continue; } - let module = fname.trim_end_matches(".ftl").replace("-", "_"); + let module = fname.trim_end_matches(".ftl").replace('-', "_"); let text = fs::read_to_string(&entry.path()).unwrap(); assert!( text.ends_with('\n'), diff --git a/rslib/i18n/build/write_strings.rs b/rslib/i18n/build/write_strings.rs index 5b15fe99d..85c460b81 100644 --- a/rslib/i18n/build/write_strings.rs +++ b/rslib/i18n/build/write_strings.rs @@ -3,9 +3,10 @@ //! Write strings to a strings.rs file that will be compiled into the binary. -use inflections::Inflect; use std::{fmt::Write, fs, path::PathBuf}; +use inflections::Inflect; + use crate::{ extract::{Module, Translation, VariableKind}, gather::{TranslationsByFile, TranslationsByLang}, @@ -42,7 +43,7 @@ impl I18n { for translation in &module.translations { let func = translation.key.to_snake_case(); let key = &translation.key; - let doc = translation.text.replace("\n", " "); + let doc = translation.text.replace('\n', " "); let in_args; let out_args; let var_build; @@ -213,7 +214,7 @@ pub(crate) const {lang_name}: phf::Map<&str, &str> = phf::phf_map! {{", } fn lang_constant_name(lang: &str) -> String { - lang.to_ascii_uppercase().replace("-", "_") + lang.to_ascii_uppercase().replace('-', "_") } fn module_constant_name(module: &str) -> String { diff --git a/rslib/src/card_rendering/writer.rs b/rslib/src/card_rendering/writer.rs index 4f9126558..b1e9f97cd 100644 --- a/rslib/src/card_rendering/writer.rs +++ b/rslib/src/card_rendering/writer.rs @@ -4,9 +4,9 @@ use std::fmt::Write as _; use super::{CardNodes, Directive, Node, OtherDirective, TtsDirective}; -use crate::prelude::*; use crate::{ backend_proto as pb, + prelude::*, text::{decode_entities, strip_html_for_tts}, }; diff --git a/rslib/src/notetype/mod.rs b/rslib/src/notetype/mod.rs index 9cc8b4f8a..233722f18 100644 --- a/rslib/src/notetype/mod.rs +++ b/rslib/src/notetype/mod.rs @@ -12,7 +12,6 @@ mod stock; mod templates; pub(crate) mod undo; -use regex::Regex; use std::{ collections::{HashMap, HashSet}, iter::FromIterator, @@ -23,6 +22,7 @@ pub(crate) use cardgen::{AlreadyGeneratedCardInfo, CardGenContext}; pub use fields::NoteField; use lazy_static::lazy_static; pub use notetypechange::{ChangeNotetypeInput, NotetypeChangeInfo}; +use regex::Regex; pub(crate) use render::RenderCardOutput; pub use schema11::{CardTemplateSchema11, NoteFieldSchema11, NotetypeSchema11}; pub use stock::all_stock_notetypes; diff --git a/rslib/src/notetype/render.rs b/rslib/src/notetype/render.rs index 10edf844e..344d9ba1f 100644 --- a/rslib/src/notetype/render.rs +++ b/rslib/src/notetype/render.rs @@ -95,10 +95,9 @@ impl Collection { ) -> Result { let mut field_map = note.fields_map(&nt.fields); - let card_num; self.add_special_fields(&mut field_map, note, card, nt, template)?; // due to lifetime restrictions we need to add card number here - card_num = format!("c{}", card.template_idx + 1); + let card_num = format!("c{}", card.template_idx + 1); field_map.entry(&card_num).or_insert_with(|| "1".into()); let (qfmt, afmt) = if browser { diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index ce754026b..e87d84ce4 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -57,7 +57,7 @@ fn write_node(node: &Node) -> String { fn write_search_node(node: &SearchNode) -> String { use SearchNode::*; match node { - UnqualifiedText(s) => maybe_quote(&s.replace(":", "\\:")), + UnqualifiedText(s) => maybe_quote(&s.replace(':', "\\:")), SingleField { field, text, is_re } => write_single_field(field, text, *is_re), AddedInDays(u) => format!("added:{}", u), EditedInDays(u) => format!("edited:{}", u), @@ -87,9 +87,9 @@ fn write_search_node(node: &SearchNode) -> String { /// Escape double quotes and wrap in double quotes if necessary. fn maybe_quote(txt: &str) -> String { if needs_quotation(txt) { - format!("\"{}\"", txt.replace("\"", "\\\"")) + format!("\"{}\"", txt.replace('\"', "\\\"")) } else { - txt.replace("\"", "\\\"") + txt.replace('\"', "\\\"") } } @@ -106,11 +106,11 @@ fn needs_quotation(txt: &str) -> bool { fn write_single_field(field: &str, text: &str, is_re: bool) -> String { let re = if is_re { "re:" } else { "" }; let text = if !is_re && text.starts_with("re:") { - text.replacen(":", "\\:", 1) + text.replacen(':', "\\:", 1) } else { text.to_string() }; - maybe_quote(&format!("{}:{}{}", field.replace(":", "\\:"), re, &text)) + maybe_quote(&format!("{}:{}{}", field.replace(':', "\\:"), re, &text)) } fn write_template(template: &TemplateKind) -> String { @@ -131,7 +131,7 @@ fn write_rated(days: &u32, ease: &RatingKind) -> String { /// Escape double quotes and backslashes: \" fn write_dupe(notetype_id: &NotetypeId, text: &str) -> String { - let esc = text.replace(r"\", r"\\"); + let esc = text.replace('\\', r"\\"); maybe_quote(&format!("dupe:{},{}", notetype_id, esc)) } diff --git a/rslib/src/tags/rename.rs b/rslib/src/tags/rename.rs index 3c427629b..253a62cd9 100644 --- a/rslib/src/tags/rename.rs +++ b/rslib/src/tags/rename.rs @@ -2,8 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::{is_tag_separator, matcher::TagMatcher}; -use crate::prelude::*; -use crate::tags::register::normalize_tag_name; +use crate::{prelude::*, tags::register::normalize_tag_name}; impl Collection { /// Rename a given tag and its children on all notes that reference it, returning changed