Skip to content

Commit 1bcc6dd

Browse files
author
Paolo Tranquilli
committed
Rust/Ruby/Python: apply clippy lints
1 parent 6089a75 commit 1bcc6dd

File tree

11 files changed

+48
-44
lines changed

11 files changed

+48
-44
lines changed

python/extractor/tsg-python/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use tree_sitter_graph::Variables;
1919
use tree_sitter_graph::ast::File;
2020
use tree_sitter_graph::functions::Functions;
2121

22-
const BUILD_VERSION: &'static str = env!("CARGO_PKG_VERSION");
22+
const BUILD_VERSION: &str = env!("CARGO_PKG_VERSION");
2323

2424
pub mod extra_functions {
2525
use tree_sitter_graph::functions::{Function, Parameters};
@@ -331,7 +331,7 @@ pub mod extra_functions {
331331
None => {
332332
return Err(ExecutionError::FunctionFailed(
333333
"unnamed-child-index".into(),
334-
format!("Cannot call child-index on the root node"),
334+
"Cannot call child-index on the root node".to_string(),
335335
));
336336
}
337337
};
@@ -342,7 +342,7 @@ pub mod extra_functions {
342342
.ok_or_else(|| {
343343
ExecutionError::FunctionFailed(
344344
"unnamed-child-index".into(),
345-
format!("Called child-index on a non-named child"),
345+
"Called child-index on a non-named child".to_string(),
346346
)
347347
})?;
348348
Ok(Value::Integer(index as u32))
@@ -400,7 +400,7 @@ pub mod extra_functions {
400400
let parent = node.parent().ok_or_else(|| {
401401
ExecutionError::FunctionFailed(
402402
"get-parent".into(),
403-
format!("Cannot call get-parent on the root node"),
403+
"Cannot call get-parent on the root node".to_string(),
404404
)
405405
})?;
406406
Ok(Value::SyntaxNode(graph.add_syntax_node(parent)))

python/extractor/tsg-python/tsp/bindings/rust/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
let src_dir = Path::new("src");
66

77
let mut c_config = cc::Build::new();
8-
c_config.include(&src_dir);
8+
c_config.include(src_dir);
99
c_config
1010
.flag_if_supported("-Wno-unused-parameter")
1111
.flag_if_supported("-Wno-unused-but-set-variable")
@@ -17,7 +17,7 @@ fn main() {
1717

1818
let mut cpp_config = cc::Build::new();
1919
cpp_config.cpp(true);
20-
cpp_config.include(&src_dir);
20+
cpp_config.include(src_dir);
2121
cpp_config
2222
.flag_if_supported("-Wno-unused-parameter")
2323
.flag_if_supported("-Wno-unused-but-set-variable");

python/extractor/tsg-python/tsp/bindings/rust/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ pub fn language() -> Language {
4343
}
4444

4545
/// The source of the Python tree-sitter grammar description.
46-
pub const GRAMMAR: &'static str = include_str!("../../grammar.js");
46+
pub const GRAMMAR: &str = include_str!("../../grammar.js");
4747

4848
/// The syntax highlighting query for this language.
49-
pub const HIGHLIGHT_QUERY: &'static str = include_str!("../../queries/highlights.scm");
49+
pub const HIGHLIGHT_QUERY: &str = include_str!("../../queries/highlights.scm");
5050

5151
/// The content of the [`node-types.json`][] file for this grammar.
5252
///
5353
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
54-
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
54+
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
5555

5656
/// The symbol tagging query for this language.
57-
pub const TAGGING_QUERY: &'static str = include_str!("../../queries/tags.scm");
57+
pub const TAGGING_QUERY: &str = include_str!("../../queries/tags.scm");
5858

5959
#[cfg(test)]
6060
mod tests {

ruby/extractor/src/extractor.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
9999
let mut needs_conversion = false;
100100
let code_ranges;
101101
let mut trap_writer = trap::Writer::new();
102-
if path.extension().map_or(false, |x| x == "erb") {
102+
if path.extension().is_some_and(|x| x == "erb") {
103103
tracing::info!("scanning: {}", path.display());
104104
extractor::extract(
105105
&erb,
@@ -371,59 +371,59 @@ fn test_scan_coding_comment() {
371371
assert_eq!(result, Some("utf-8".into()));
372372

373373
let text = "#coding:utf-8";
374-
let result = scan_coding_comment(&text.as_bytes());
374+
let result = scan_coding_comment(text.as_bytes());
375375
assert_eq!(result, Some("utf-8".into()));
376376

377377
let text = "# foo\n# encoding: utf-8";
378-
let result = scan_coding_comment(&text.as_bytes());
378+
let result = scan_coding_comment(text.as_bytes());
379379
assert_eq!(result, None);
380380

381381
let text = "# encoding: latin1 encoding: utf-8";
382-
let result = scan_coding_comment(&text.as_bytes());
382+
let result = scan_coding_comment(text.as_bytes());
383383
assert_eq!(result, Some("latin1".into()));
384384

385385
let text = "# encoding: nonsense";
386-
let result = scan_coding_comment(&text.as_bytes());
386+
let result = scan_coding_comment(text.as_bytes());
387387
assert_eq!(result, Some("nonsense".into()));
388388

389389
let text = "# coding = utf-8";
390-
let result = scan_coding_comment(&text.as_bytes());
390+
let result = scan_coding_comment(text.as_bytes());
391391
assert_eq!(result, Some("utf-8".into()));
392392

393393
let text = "# CODING = utf-8";
394-
let result = scan_coding_comment(&text.as_bytes());
394+
let result = scan_coding_comment(text.as_bytes());
395395
assert_eq!(result, Some("utf-8".into()));
396396

397397
let text = "# CoDiNg = utf-8";
398-
let result = scan_coding_comment(&text.as_bytes());
398+
let result = scan_coding_comment(text.as_bytes());
399399
assert_eq!(result, Some("utf-8".into()));
400400

401401
let text = "# blah blahblahcoding = utf-8";
402-
let result = scan_coding_comment(&text.as_bytes());
402+
let result = scan_coding_comment(text.as_bytes());
403403
assert_eq!(result, Some("utf-8".into()));
404404

405405
// unicode BOM is ignored
406406
let text = "\u{FEFF}# encoding: utf-8";
407-
let result = scan_coding_comment(&text.as_bytes());
407+
let result = scan_coding_comment(text.as_bytes());
408408
assert_eq!(result, Some("utf-8".into()));
409409

410410
let text = "\u{FEFF} # encoding: utf-8";
411-
let result = scan_coding_comment(&text.as_bytes());
411+
let result = scan_coding_comment(text.as_bytes());
412412
assert_eq!(result, Some("utf-8".into()));
413413

414414
let text = "#! /usr/bin/env ruby\n # encoding: utf-8";
415-
let result = scan_coding_comment(&text.as_bytes());
415+
let result = scan_coding_comment(text.as_bytes());
416416
assert_eq!(result, Some("utf-8".into()));
417417

418418
let text = "\u{FEFF}#! /usr/bin/env ruby\n # encoding: utf-8";
419-
let result = scan_coding_comment(&text.as_bytes());
419+
let result = scan_coding_comment(text.as_bytes());
420420
assert_eq!(result, Some("utf-8".into()));
421421

422422
// A #! must be the first thing on a line, otherwise it's a normal comment
423423
let text = " #! /usr/bin/env ruby encoding = utf-8";
424-
let result = scan_coding_comment(&text.as_bytes());
424+
let result = scan_coding_comment(text.as_bytes());
425425
assert_eq!(result, Some("utf-8".into()));
426426
let text = " #! /usr/bin/env ruby \n # encoding = utf-8";
427-
let result = scan_coding_comment(&text.as_bytes());
427+
let result = scan_coding_comment(text.as_bytes());
428428
assert_eq!(result, None);
429429
}

shared/tree-sitter-extractor/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl LogWriter {
124124
match std::fs::OpenOptions::new()
125125
.create(true)
126126
.append(true)
127-
.write(true)
127+
128128
.open(path)
129129
{
130130
Err(e) => {

shared/tree-sitter-extractor/src/generator/dbscheme.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub enum DbColumnType {
4848
String,
4949
}
5050

51-
impl<'a> fmt::Display for Case<'a> {
51+
impl fmt::Display for Case<'_> {
5252
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5353
writeln!(f, "case @{}.{} of", &self.name, &self.column)?;
5454
let mut sep = " ";
@@ -60,7 +60,7 @@ impl<'a> fmt::Display for Case<'a> {
6060
}
6161
}
6262

63-
impl<'a> fmt::Display for Table<'a> {
63+
impl fmt::Display for Table<'_> {
6464
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6565
if let Some(keyset) = &self.keysets {
6666
write!(f, "#keyset[")?;
@@ -102,7 +102,7 @@ impl<'a> fmt::Display for Table<'a> {
102102
}
103103
}
104104

105-
impl<'a> fmt::Display for Union<'a> {
105+
impl fmt::Display for Union<'_> {
106106
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
107107
write!(f, "@{} = ", self.name)?;
108108
let mut first = true;

shared/tree-sitter-extractor/src/generator/ql.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub enum TopLevel<'a> {
88
Module(Module<'a>),
99
}
1010

11-
impl<'a> fmt::Display for TopLevel<'a> {
11+
impl fmt::Display for TopLevel<'_> {
1212
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1313
match self {
1414
TopLevel::Import(imp) => write!(f, "{}", imp),
@@ -24,7 +24,7 @@ pub struct Import<'a> {
2424
pub alias: Option<&'a str>,
2525
}
2626

27-
impl<'a> fmt::Display for Import<'a> {
27+
impl fmt::Display for Import<'_> {
2828
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2929
write!(f, "import {}", &self.module)?;
3030
if let Some(name) = &self.alias {
@@ -43,7 +43,7 @@ pub struct Class<'a> {
4343
pub predicates: Vec<Predicate<'a>>,
4444
}
4545

46-
impl<'a> fmt::Display for Class<'a> {
46+
impl fmt::Display for Class<'_> {
4747
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4848
if let Some(qldoc) = &self.qldoc {
4949
write!(f, "/** {} */", qldoc)?;
@@ -93,7 +93,7 @@ pub struct Module<'a> {
9393
pub body: Vec<TopLevel<'a>>,
9494
}
9595

96-
impl<'a> fmt::Display for Module<'a> {
96+
impl fmt::Display for Module<'_> {
9797
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9898
if let Some(qldoc) = &self.qldoc {
9999
write!(f, "/** {} */", qldoc)?;
@@ -122,7 +122,7 @@ pub enum Type<'a> {
122122
Normal(&'a str),
123123
}
124124

125-
impl<'a> fmt::Display for Type<'a> {
125+
impl fmt::Display for Type<'_> {
126126
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
127127
match self {
128128
Type::Int => write!(f, "int"),
@@ -152,7 +152,7 @@ pub enum Expression<'a> {
152152
},
153153
}
154154

155-
impl<'a> fmt::Display for Expression<'a> {
155+
impl fmt::Display for Expression<'_> {
156156
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
157157
match self {
158158
Expression::Var(x) => write!(f, "{}", x),
@@ -246,7 +246,7 @@ pub struct Predicate<'a> {
246246
pub body: Expression<'a>,
247247
}
248248

249-
impl<'a> fmt::Display for Predicate<'a> {
249+
impl fmt::Display for Predicate<'_> {
250250
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
251251
if let Some(qldoc) = &self.qldoc {
252252
write!(f, "/** {} */", qldoc)?;
@@ -280,7 +280,7 @@ pub struct FormalParameter<'a> {
280280
pub param_type: Type<'a>,
281281
}
282282

283-
impl<'a> fmt::Display for FormalParameter<'a> {
283+
impl fmt::Display for FormalParameter<'_> {
284284
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
285285
write!(f, "{} {}", self.param_type, self.name)
286286
}

shared/tree-sitter-extractor/src/trap.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ pub struct Writer {
2525
location_labels: std::collections::HashMap<Location, Label>,
2626
}
2727

28+
impl Default for Writer {
29+
fn default() -> Self {
30+
Self::new()
31+
}
32+
}
33+
2834
impl Writer {
2935
pub fn new() -> Writer {
3036
Writer {
@@ -306,9 +312,9 @@ impl Compression {
306312

307313
#[test]
308314
fn limit_string_test() {
309-
assert_eq!("hello", limit_string(&"hello world".to_owned(), 5));
310-
assert_eq!("hi ☹", limit_string(&"hi ☹☹".to_owned(), 6));
311-
assert_eq!("hi ", limit_string(&"hi ☹☹".to_owned(), 5));
315+
assert_eq!("hello", limit_string("hello world", 5));
316+
assert_eq!("hi ☹", limit_string("hi ☹☹", 6));
317+
assert_eq!("hi ", limit_string("hi ☹☹", 5));
312318
}
313319

314320
#[test]

shared/tree-sitter-extractor/tests/common/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn create_source_dir(files: Vec<(&'static str, &'static str)>) -> SourceArch
2828
let path = source_archive_dir.join(filename);
2929
let mut file = File::create(&path).unwrap();
3030
file.write_all(contents.as_bytes()).unwrap();
31-
file_paths.push(PathBuf::from(path));
31+
file_paths.push(path);
3232
}
3333

3434
let file_list = {
@@ -69,5 +69,5 @@ pub fn expect_trap_file(root_dir: &Path, filename: &str) {
6969
fn create_dir(root: &Path, path: impl AsRef<Path>) -> PathBuf {
7070
let full_path = root.join(path);
7171
std::fs::create_dir_all(&full_path).expect("Failed to create directory");
72-
full_path.into()
72+
full_path
7373
}

shared/tree-sitter-extractor/tests/integration_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use codeql_extractor::extractor::simple;
22
use codeql_extractor::trap;
33

4-
use tree_sitter_ql;
54

65
mod common;
76
use common::{SourceArchive, create_source_dir, expect_trap_file};

0 commit comments

Comments
 (0)