Shared tree-sitter extractor: run clippy

This commit is contained in:
Paolo Tranquilli
2025-08-11 17:04:22 +02:00
parent 45c0c46c9d
commit 911d6f07b6
9 changed files with 59 additions and 59 deletions

View File

@@ -57,23 +57,23 @@ impl Autobuilder {
let verbosity = env::var("CODEQL_VERBOSITY");
if let Ok(verbosity) = verbosity {
cmd.arg(format!("--verbosity={}", verbosity));
cmd.arg(format!("--verbosity={verbosity}"));
}
for ext in &self.include_extensions {
cmd.arg(format!("--include-extension={}", ext));
cmd.arg(format!("--include-extension={ext}"));
}
for glob in &self.include_globs {
cmd.arg(format!("--include={}", glob));
cmd.arg(format!("--include={glob}"));
}
for glob in &self.exclude_globs {
cmd.arg(format!("--exclude={}", glob));
cmd.arg(format!("--exclude={glob}"));
}
if let Some(limit) = &self.size_limit {
cmd.arg(format!("--size-limit={}", limit));
cmd.arg(format!("--size-limit={limit}"));
}
cmd.arg(format!("--language={}", &self.language));

View File

@@ -194,7 +194,7 @@ impl DiagnosticLoggers {
path: self
.root
.as_ref()
.map(|root| root.to_owned().join(format!("extractor_{}.jsonl", n))),
.map(|root| root.to_owned().join(format!("extractor_{n}.jsonl"))),
})
}
}

View File

@@ -230,7 +230,7 @@ pub fn extract(
parser.set_language(language).unwrap();
parser.set_included_ranges(ranges).unwrap();
let tree = parser.parse(source, None).expect("Failed to parse file");
trap_writer.comment(format!("Auto-generated TRAP file for {}", path_str));
trap_writer.comment(format!("Auto-generated TRAP file for {path_str}"));
let file_label = populate_file(trap_writer, path, transformer);
let mut visitor = Visitor::new(
source,
@@ -298,9 +298,9 @@ impl<'a> Visitor<'a> {
source,
diagnostics_writer,
trap_writer,
ast_node_location_table_name: format!("{}_ast_node_location", language_prefix),
ast_node_parent_table_name: format!("{}_ast_node_parent", language_prefix),
tokeninfo_table_name: format!("{}_tokeninfo", language_prefix),
ast_node_location_table_name: format!("{language_prefix}_ast_node_location"),
ast_node_parent_table_name: format!("{language_prefix}_ast_node_parent"),
tokeninfo_table_name: format!("{language_prefix}_tokeninfo"),
schema,
stack: Vec::new(),
}

View File

@@ -80,7 +80,7 @@ impl Extractor {
.iter()
.map(|file_list| {
File::open(file_list)
.unwrap_or_else(|_| panic!("Unable to open file list at {:?}", file_list))
.unwrap_or_else(|_| panic!("Unable to open file list at {file_list:?}"))
})
.collect();

View File

@@ -53,7 +53,7 @@ impl fmt::Display for Case<'_> {
writeln!(f, "case @{}.{} of", &self.name, &self.column)?;
let mut sep = " ";
for (c, tp) in &self.branches {
writeln!(f, "{} {} = @{}", sep, c, tp)?;
writeln!(f, "{sep} {c} = @{tp}")?;
sep = "|";
}
writeln!(f, ";")
@@ -68,7 +68,7 @@ impl fmt::Display for Table<'_> {
if key_index > 0 {
write!(f, ", ")?;
}
write!(f, "{}", key)?;
write!(f, "{key}")?;
}
writeln!(f, "]")?;
}
@@ -112,7 +112,7 @@ impl fmt::Display for Union<'_> {
} else {
write!(f, " | ")?;
}
write!(f, "@{}", member)?;
write!(f, "@{member}")?;
}
Ok(())
}
@@ -122,9 +122,9 @@ impl fmt::Display for Union<'_> {
pub fn write(file: &mut dyn std::io::Write, entries: &[Entry]) -> std::io::Result<()> {
for entry in entries {
match entry {
Entry::Case(case) => write!(file, "{}\n\n", case)?,
Entry::Table(table) => write!(file, "{}\n\n", table)?,
Entry::Union(union) => write!(file, "{}\n\n", union)?,
Entry::Case(case) => write!(file, "{case}\n\n")?,
Entry::Table(table) => write!(file, "{table}\n\n")?,
Entry::Union(union) => write!(file, "{union}\n\n")?,
}
}

View File

@@ -12,10 +12,10 @@ pub enum TopLevel<'a> {
impl fmt::Display for TopLevel<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
TopLevel::Import(imp) => write!(f, "{}", imp),
TopLevel::Class(cls) => write!(f, "{}", cls),
TopLevel::Module(m) => write!(f, "{}", m),
TopLevel::Predicate(pred) => write!(f, "{}", pred),
TopLevel::Import(imp) => write!(f, "{imp}"),
TopLevel::Class(cls) => write!(f, "{cls}"),
TopLevel::Module(m) => write!(f, "{m}"),
TopLevel::Predicate(pred) => write!(f, "{pred}"),
}
}
}
@@ -30,7 +30,7 @@ impl fmt::Display for Import<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "import {}", &self.module)?;
if let Some(name) = &self.alias {
write!(f, " as {}", name)?;
write!(f, " as {name}")?;
}
Ok(())
}
@@ -48,7 +48,7 @@ pub struct Class<'a> {
impl fmt::Display for Class<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(qldoc) = &self.qldoc {
write!(f, "/** {} */", qldoc)?;
write!(f, "/** {qldoc} */")?;
}
if self.is_abstract {
write!(f, "abstract ")?;
@@ -58,7 +58,7 @@ impl fmt::Display for Class<'_> {
if index > 0 {
write!(f, ", ")?;
}
write!(f, "{}", supertype)?;
write!(f, "{supertype}")?;
}
writeln!(f, " {{ ")?;
@@ -81,7 +81,7 @@ impl fmt::Display for Class<'_> {
}
for predicate in &self.predicates {
writeln!(f, " {}", predicate)?;
writeln!(f, " {predicate}")?;
}
write!(f, "}}")?;
@@ -101,7 +101,7 @@ pub struct Module<'a> {
impl fmt::Display for Module<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(qldoc) = &self.qldoc {
write!(f, "/** {} */", qldoc)?;
write!(f, "/** {qldoc} */")?;
}
if let Some(overlay_annotation) = &self.overlay {
write!(f, "overlay[")?;
@@ -113,7 +113,7 @@ impl fmt::Display for Module<'_> {
}
writeln!(f, "module {} {{ ", self.name)?;
for decl in &self.body {
writeln!(f, " {}", decl)?;
writeln!(f, " {decl}")?;
}
write!(f, "}}")?;
Ok(())
@@ -140,8 +140,8 @@ impl fmt::Display for Type<'_> {
match self {
Type::Int => write!(f, "int"),
Type::String => write!(f, "string"),
Type::Normal(name) => write!(f, "{}", name),
Type::At(name) => write!(f, "@{}", name),
Type::Normal(name) => write!(f, "{name}"),
Type::At(name) => write!(f, "@{name}"),
}
}
}
@@ -169,16 +169,16 @@ pub enum Expression<'a> {
impl fmt::Display for Expression<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expression::Var(x) => write!(f, "{}", x),
Expression::String(s) => write!(f, "\"{}\"", s),
Expression::Integer(n) => write!(f, "{}", n),
Expression::Var(x) => write!(f, "{x}"),
Expression::String(s) => write!(f, "\"{s}\""),
Expression::Integer(n) => write!(f, "{n}"),
Expression::Pred(n, args) => {
write!(f, "{}(", n)?;
write!(f, "{n}(")?;
for (index, arg) in args.iter().enumerate() {
if index > 0 {
write!(f, ", ")?;
}
write!(f, "{}", arg)?;
write!(f, "{arg}")?;
}
write!(f, ")")
}
@@ -190,7 +190,7 @@ impl fmt::Display for Expression<'_> {
if index > 0 {
write!(f, " and ")?;
}
write!(f, "({})", conjunct)?;
write!(f, "({conjunct})")?;
}
Ok(())
}
@@ -203,19 +203,19 @@ impl fmt::Display for Expression<'_> {
if index > 0 {
write!(f, " or ")?;
}
write!(f, "({})", disjunct)?;
write!(f, "({disjunct})")?;
}
Ok(())
}
}
Expression::Equals(a, b) => write!(f, "{} = {}", a, b),
Expression::Equals(a, b) => write!(f, "{a} = {b}"),
Expression::Dot(x, member_pred, args) => {
write!(f, "{}.{}(", x, member_pred)?;
write!(f, "{x}.{member_pred}(")?;
for (index, arg) in args.iter().enumerate() {
if index > 0 {
write!(f, ", ")?;
}
write!(f, "{}", arg)?;
write!(f, "{arg}")?;
}
write!(f, ")")
}
@@ -226,26 +226,26 @@ impl fmt::Display for Expression<'_> {
expr,
second_expr,
} => {
write!(f, "{}(", name)?;
write!(f, "{name}(")?;
if !vars.is_empty() {
for (index, var) in vars.iter().enumerate() {
if index > 0 {
write!(f, ", ")?;
}
write!(f, "{}", var)?;
write!(f, "{var}")?;
}
write!(f, " | ")?;
}
if let Some(range) = range {
write!(f, "{} | ", range)?;
write!(f, "{range} | ")?;
}
write!(f, "{}", expr)?;
write!(f, "{expr}")?;
if let Some(second_expr) = second_expr {
write!(f, ", {}", second_expr)?;
write!(f, ", {second_expr}")?;
}
write!(f, ")")
}
Expression::Negation(e) => write!(f, "not ({})", e),
Expression::Negation(e) => write!(f, "not ({e})"),
}
}
}
@@ -272,7 +272,7 @@ pub struct Predicate<'a> {
impl fmt::Display for Predicate<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(qldoc) = &self.qldoc {
write!(f, "/** {} */", qldoc)?;
write!(f, "/** {qldoc} */")?;
}
if let Some(overlay_annotation) = &self.overlay {
write!(f, "overlay[")?;
@@ -293,14 +293,14 @@ impl fmt::Display for Predicate<'_> {
}
match &self.return_type {
None => write!(f, "predicate ")?,
Some(return_type) => write!(f, "{} ", return_type)?,
Some(return_type) => write!(f, "{return_type} ")?,
}
write!(f, "{}(", self.name)?;
for (index, param) in self.formal_parameters.iter().enumerate() {
if index > 0 {
write!(f, ", ")?;
}
write!(f, "{}", param)?;
write!(f, "{param}")?;
}
write!(f, ") {{ {} }}", self.body)?;

View File

@@ -666,7 +666,7 @@ fn create_field_getters<'a>(
}
};
let qldoc = match &field.name {
Some(name) => format!("Gets the node corresponding to the field `{}`.", name),
Some(name) => format!("Gets the node corresponding to the field `{name}`."),
None => {
if formal_parameters.is_empty() {
"Gets the child of this node.".to_owned()

View File

@@ -326,7 +326,7 @@ fn node_type_name(kind: &str, named: bool) -> String {
if named {
kind.to_string()
} else {
format!("{}_unnamed", kind)
format!("{kind}_unnamed")
}
}

View File

@@ -112,7 +112,7 @@ impl Writer {
fn write_trap_entries<W: Write>(&self, file: &mut W) -> std::io::Result<()> {
for trap_entry in &self.trap_output {
writeln!(file, "{}", trap_entry)?;
writeln!(file, "{trap_entry}")?;
}
Ok(())
}
@@ -131,21 +131,21 @@ pub enum Entry {
impl fmt::Display for Entry {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Entry::FreshId(label) => write!(f, "{}=*", label),
Entry::FreshId(label) => write!(f, "{label}=*"),
Entry::MapLabelToKey(label, key) => {
write!(f, "{}=@\"{}\"", label, key.replace('"', "\"\""))
}
Entry::GenericTuple(name, args) => {
write!(f, "{}(", name)?;
write!(f, "{name}(")?;
for (index, arg) in args.iter().enumerate() {
if index > 0 {
write!(f, ",")?;
}
write!(f, "{}", arg)?;
write!(f, "{arg}")?;
}
write!(f, ")")
}
Entry::Comment(line) => write!(f, "// {}", line),
Entry::Comment(line) => write!(f, "// {line}"),
}
}
}
@@ -179,8 +179,8 @@ const MAX_STRLEN: usize = 1048576;
impl fmt::Display for Arg {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Arg::Label(x) => write!(f, "{}", x),
Arg::Int(x) => write!(f, "{}", x),
Arg::Label(x) => write!(f, "{x}"),
Arg::Int(x) => write!(f, "{x}"),
Arg::String(x) => write!(
f,
"\"{}\"",
@@ -220,9 +220,9 @@ impl fmt::Display for Program {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut text = String::new();
for trap_entry in &self.0 {
text.push_str(&format!("{}\n", trap_entry));
text.push_str(&format!("{trap_entry}\n"));
}
write!(f, "{}", text)
write!(f, "{text}")
}
}