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"); let verbosity = env::var("CODEQL_VERBOSITY");
if let Ok(verbosity) = verbosity { if let Ok(verbosity) = verbosity {
cmd.arg(format!("--verbosity={}", verbosity)); cmd.arg(format!("--verbosity={verbosity}"));
} }
for ext in &self.include_extensions { for ext in &self.include_extensions {
cmd.arg(format!("--include-extension={}", ext)); cmd.arg(format!("--include-extension={ext}"));
} }
for glob in &self.include_globs { for glob in &self.include_globs {
cmd.arg(format!("--include={}", glob)); cmd.arg(format!("--include={glob}"));
} }
for glob in &self.exclude_globs { for glob in &self.exclude_globs {
cmd.arg(format!("--exclude={}", glob)); cmd.arg(format!("--exclude={glob}"));
} }
if let Some(limit) = &self.size_limit { 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)); cmd.arg(format!("--language={}", &self.language));

View File

@@ -194,7 +194,7 @@ impl DiagnosticLoggers {
path: self path: self
.root .root
.as_ref() .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_language(language).unwrap();
parser.set_included_ranges(ranges).unwrap(); parser.set_included_ranges(ranges).unwrap();
let tree = parser.parse(source, None).expect("Failed to parse file"); 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 file_label = populate_file(trap_writer, path, transformer);
let mut visitor = Visitor::new( let mut visitor = Visitor::new(
source, source,
@@ -298,9 +298,9 @@ impl<'a> Visitor<'a> {
source, source,
diagnostics_writer, diagnostics_writer,
trap_writer, trap_writer,
ast_node_location_table_name: format!("{}_ast_node_location", language_prefix), ast_node_location_table_name: format!("{language_prefix}_ast_node_location"),
ast_node_parent_table_name: format!("{}_ast_node_parent", language_prefix), ast_node_parent_table_name: format!("{language_prefix}_ast_node_parent"),
tokeninfo_table_name: format!("{}_tokeninfo", language_prefix), tokeninfo_table_name: format!("{language_prefix}_tokeninfo"),
schema, schema,
stack: Vec::new(), stack: Vec::new(),
} }

View File

@@ -80,7 +80,7 @@ impl Extractor {
.iter() .iter()
.map(|file_list| { .map(|file_list| {
File::open(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(); .collect();

View File

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

View File

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

View File

@@ -666,7 +666,7 @@ fn create_field_getters<'a>(
} }
}; };
let qldoc = match &field.name { 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 => { None => {
if formal_parameters.is_empty() { if formal_parameters.is_empty() {
"Gets the child of this node.".to_owned() "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 { if named {
kind.to_string() kind.to_string()
} else { } 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<()> { fn write_trap_entries<W: Write>(&self, file: &mut W) -> std::io::Result<()> {
for trap_entry in &self.trap_output { for trap_entry in &self.trap_output {
writeln!(file, "{}", trap_entry)?; writeln!(file, "{trap_entry}")?;
} }
Ok(()) Ok(())
} }
@@ -131,21 +131,21 @@ pub enum Entry {
impl fmt::Display for Entry { impl fmt::Display for Entry {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
Entry::FreshId(label) => write!(f, "{}=*", label), Entry::FreshId(label) => write!(f, "{label}=*"),
Entry::MapLabelToKey(label, key) => { Entry::MapLabelToKey(label, key) => {
write!(f, "{}=@\"{}\"", label, key.replace('"', "\"\"")) write!(f, "{}=@\"{}\"", label, key.replace('"', "\"\""))
} }
Entry::GenericTuple(name, args) => { Entry::GenericTuple(name, args) => {
write!(f, "{}(", name)?; write!(f, "{name}(")?;
for (index, arg) in args.iter().enumerate() { for (index, arg) in args.iter().enumerate() {
if index > 0 { if index > 0 {
write!(f, ",")?; write!(f, ",")?;
} }
write!(f, "{}", arg)?; write!(f, "{arg}")?;
} }
write!(f, ")") 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 { impl fmt::Display for Arg {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
Arg::Label(x) => write!(f, "{}", x), Arg::Label(x) => write!(f, "{x}"),
Arg::Int(x) => write!(f, "{}", x), Arg::Int(x) => write!(f, "{x}"),
Arg::String(x) => write!( Arg::String(x) => write!(
f, f,
"\"{}\"", "\"{}\"",
@@ -220,9 +220,9 @@ impl fmt::Display for Program {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut text = String::new(); let mut text = String::new();
for trap_entry in &self.0 { 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}")
} }
} }