Fix some clippy lints + imports

This commit is contained in:
Damien Elmes 2022-03-17 21:03:06 +10:00
parent bf8e70c70f
commit dadb69a14b
7 changed files with 20 additions and 19 deletions

View File

@ -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<String, String>;
pub type TranslationsByLang = HashMap<String, TranslationsByFile>;
@ -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'),

View File

@ -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 {

View File

@ -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},
};

View File

@ -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;

View File

@ -95,10 +95,9 @@ impl Collection {
) -> Result<RenderCardOutput> {
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 {

View File

@ -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))
}

View File

@ -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