clippy fixes

This commit is contained in:
Robin Appelman 2024-09-15 16:10:06 +02:00
commit 6f27c4fb76
3 changed files with 15 additions and 20 deletions

View file

@ -47,7 +47,7 @@ fn build_pattern(parts: &[crate::MessagePart]) -> String {
match part { match part {
crate::MessagePart::Literal(literal) => pattern.push_str(literal.as_str()), crate::MessagePart::Literal(literal) => pattern.push_str(literal.as_str()),
crate::MessagePart::PlaceHolder(_placeholder) => { crate::MessagePart::PlaceHolder(_placeholder) => {
pattern.push_str("\0"); pattern.push('\0');
} }
} }
} }

View file

@ -108,11 +108,14 @@ impl MessageBuilder {
node.child_by_field_name("arguments").expect("no arguments"); node.child_by_field_name("arguments").expect("no arguments");
let mut arguments = arguments.children(&mut cursor).skip(1); // opening bracket let mut arguments = arguments.children(&mut cursor).skip(1); // opening bracket
let mut cursor = node.walk(); let mut cursor = node.walk();
let fmt = string_parts(arguments.next().unwrap().child(0).unwrap(), code, &mut cursor); let fmt = string_parts(
let mut arguments = arguments.filter_map(|arg| { arguments.next().unwrap().child(0).unwrap(),
(arg.grammar_name() != ",") code,
.then(|| arg.utf8_text(code.as_bytes()).unwrap()) &mut cursor,
}); );
let mut arguments = arguments
.filter(|arg| arg.grammar_name() != ",")
.map(|arg| arg.utf8_text(code.as_bytes()).unwrap());
for part in fmt { for part in fmt {
match part { match part {
MessagePart::Literal(lit) => self.push_printf(&lit, &mut arguments), MessagePart::Literal(lit) => self.push_printf(&lit, &mut arguments),
@ -173,7 +176,7 @@ fn string_parts<'cursor, 'node: 'cursor>(
unescape::<SingleQuoteString>(raw) unescape::<SingleQuoteString>(raw)
} }
.unwrap(); .unwrap();
Some(MessagePart::Literal(content.into())) Some(MessagePart::Literal(content))
} }
r#"'"# | r#"""# | r#"{"# | r#"}"# => None, r#"'"# | r#"""# | r#"{"# | r#"}"# => None,
_ => { _ => {

View file

@ -1,28 +1,20 @@
use std::collections::HashMap; use std::collections::HashMap;
pub fn resolve_name(namespace: &str, aliases: &HashMap<&str, &str>, class: &str) -> String { pub fn resolve_name(namespace: &str, aliases: &HashMap<&str, &str>, class: &str) -> String {
if class.starts_with('\\') { if let Some(stripped) = class.strip_prefix('\\') {
return class[1..].into(); return stripped.into();
} }
let (first_part, rest) = class.split_once('\\').unwrap_or((class, "")); let (first_part, rest) = class.split_once('\\').unwrap_or((class, ""));
if let Some(alias) = aliases.get(first_part) { if let Some(alias) = aliases.get(first_part) {
if rest.is_empty() { if rest.is_empty() {
format!("{alias}") alias.to_string()
} else { } else {
format!("{alias}\\{rest}") format!("{alias}\\{rest}")
} }
} else if namespace.is_empty() { } else if namespace.is_empty() {
if rest.is_empty() { class.to_string()
format!("{first_part}")
} else { } else {
format!("{first_part}\\{rest}") format!("{namespace}\\{class}")
}
} else {
if rest.is_empty() {
format!("{namespace}\\{first_part}")
} else {
format!("{namespace}\\{first_part}\\{rest}")
}
} }
} }