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

View file

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