mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Fix some clippy lints + imports
This commit is contained in:
parent
bf8e70c70f
commit
dadb69a14b
7 changed files with 20 additions and 19 deletions
|
@ -10,9 +10,11 @@
|
||||||
//! repo. If it is pointed at a different location, the Qt translations will be excluded
|
//! repo. If it is pointed at a different location, the Qt translations will be excluded
|
||||||
//! and the provided translations embedded instead.
|
//! and the provided translations embedded instead.
|
||||||
|
|
||||||
use std::path::Path;
|
use std::{
|
||||||
use std::{collections::HashMap, env};
|
collections::HashMap,
|
||||||
use std::{fs, path::PathBuf};
|
env, fs,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
pub type TranslationsByFile = HashMap<String, String>;
|
pub type TranslationsByFile = HashMap<String, String>;
|
||||||
pub type TranslationsByLang = HashMap<String, TranslationsByFile>;
|
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") {
|
if !fname.ends_with(".ftl") {
|
||||||
continue;
|
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();
|
let text = fs::read_to_string(&entry.path()).unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
text.ends_with('\n'),
|
text.ends_with('\n'),
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
//! Write strings to a strings.rs file that will be compiled into the binary.
|
//! 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 std::{fmt::Write, fs, path::PathBuf};
|
||||||
|
|
||||||
|
use inflections::Inflect;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
extract::{Module, Translation, VariableKind},
|
extract::{Module, Translation, VariableKind},
|
||||||
gather::{TranslationsByFile, TranslationsByLang},
|
gather::{TranslationsByFile, TranslationsByLang},
|
||||||
|
@ -42,7 +43,7 @@ impl I18n {
|
||||||
for translation in &module.translations {
|
for translation in &module.translations {
|
||||||
let func = translation.key.to_snake_case();
|
let func = translation.key.to_snake_case();
|
||||||
let key = &translation.key;
|
let key = &translation.key;
|
||||||
let doc = translation.text.replace("\n", " ");
|
let doc = translation.text.replace('\n', " ");
|
||||||
let in_args;
|
let in_args;
|
||||||
let out_args;
|
let out_args;
|
||||||
let var_build;
|
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 {
|
fn lang_constant_name(lang: &str) -> String {
|
||||||
lang.to_ascii_uppercase().replace("-", "_")
|
lang.to_ascii_uppercase().replace('-', "_")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn module_constant_name(module: &str) -> String {
|
fn module_constant_name(module: &str) -> String {
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
|
|
||||||
use super::{CardNodes, Directive, Node, OtherDirective, TtsDirective};
|
use super::{CardNodes, Directive, Node, OtherDirective, TtsDirective};
|
||||||
use crate::prelude::*;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
|
prelude::*,
|
||||||
text::{decode_entities, strip_html_for_tts},
|
text::{decode_entities, strip_html_for_tts},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ mod stock;
|
||||||
mod templates;
|
mod templates;
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
||||||
use regex::Regex;
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
iter::FromIterator,
|
iter::FromIterator,
|
||||||
|
@ -23,6 +22,7 @@ pub(crate) use cardgen::{AlreadyGeneratedCardInfo, CardGenContext};
|
||||||
pub use fields::NoteField;
|
pub use fields::NoteField;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
pub use notetypechange::{ChangeNotetypeInput, NotetypeChangeInfo};
|
pub use notetypechange::{ChangeNotetypeInput, NotetypeChangeInfo};
|
||||||
|
use regex::Regex;
|
||||||
pub(crate) use render::RenderCardOutput;
|
pub(crate) use render::RenderCardOutput;
|
||||||
pub use schema11::{CardTemplateSchema11, NoteFieldSchema11, NotetypeSchema11};
|
pub use schema11::{CardTemplateSchema11, NoteFieldSchema11, NotetypeSchema11};
|
||||||
pub use stock::all_stock_notetypes;
|
pub use stock::all_stock_notetypes;
|
||||||
|
|
|
@ -95,10 +95,9 @@ impl Collection {
|
||||||
) -> Result<RenderCardOutput> {
|
) -> Result<RenderCardOutput> {
|
||||||
let mut field_map = note.fields_map(&nt.fields);
|
let mut field_map = note.fields_map(&nt.fields);
|
||||||
|
|
||||||
let card_num;
|
|
||||||
self.add_special_fields(&mut field_map, note, card, nt, template)?;
|
self.add_special_fields(&mut field_map, note, card, nt, template)?;
|
||||||
// due to lifetime restrictions we need to add card number here
|
// 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());
|
field_map.entry(&card_num).or_insert_with(|| "1".into());
|
||||||
|
|
||||||
let (qfmt, afmt) = if browser {
|
let (qfmt, afmt) = if browser {
|
||||||
|
|
|
@ -57,7 +57,7 @@ fn write_node(node: &Node) -> String {
|
||||||
fn write_search_node(node: &SearchNode) -> String {
|
fn write_search_node(node: &SearchNode) -> String {
|
||||||
use SearchNode::*;
|
use SearchNode::*;
|
||||||
match node {
|
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),
|
SingleField { field, text, is_re } => write_single_field(field, text, *is_re),
|
||||||
AddedInDays(u) => format!("added:{}", u),
|
AddedInDays(u) => format!("added:{}", u),
|
||||||
EditedInDays(u) => format!("edited:{}", 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.
|
/// Escape double quotes and wrap in double quotes if necessary.
|
||||||
fn maybe_quote(txt: &str) -> String {
|
fn maybe_quote(txt: &str) -> String {
|
||||||
if needs_quotation(txt) {
|
if needs_quotation(txt) {
|
||||||
format!("\"{}\"", txt.replace("\"", "\\\""))
|
format!("\"{}\"", txt.replace('\"', "\\\""))
|
||||||
} else {
|
} 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 {
|
fn write_single_field(field: &str, text: &str, is_re: bool) -> String {
|
||||||
let re = if is_re { "re:" } else { "" };
|
let re = if is_re { "re:" } else { "" };
|
||||||
let text = if !is_re && text.starts_with("re:") {
|
let text = if !is_re && text.starts_with("re:") {
|
||||||
text.replacen(":", "\\:", 1)
|
text.replacen(':', "\\:", 1)
|
||||||
} else {
|
} else {
|
||||||
text.to_string()
|
text.to_string()
|
||||||
};
|
};
|
||||||
maybe_quote(&format!("{}:{}{}", field.replace(":", "\\:"), re, &text))
|
maybe_quote(&format!("{}:{}{}", field.replace(':', "\\:"), re, &text))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_template(template: &TemplateKind) -> String {
|
fn write_template(template: &TemplateKind) -> String {
|
||||||
|
@ -131,7 +131,7 @@ fn write_rated(days: &u32, ease: &RatingKind) -> String {
|
||||||
|
|
||||||
/// Escape double quotes and backslashes: \"
|
/// Escape double quotes and backslashes: \"
|
||||||
fn write_dupe(notetype_id: &NotetypeId, text: &str) -> String {
|
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))
|
maybe_quote(&format!("dupe:{},{}", notetype_id, esc))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::{is_tag_separator, matcher::TagMatcher};
|
use super::{is_tag_separator, matcher::TagMatcher};
|
||||||
use crate::prelude::*;
|
use crate::{prelude::*, tags::register::normalize_tag_name};
|
||||||
use crate::tags::register::normalize_tag_name;
|
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
/// Rename a given tag and its children on all notes that reference it, returning changed
|
/// Rename a given tag and its children on all notes that reference it, returning changed
|
||||||
|
|
Loading…
Reference in a new issue