Rust/Ruby/Python: apply clippy lints

This commit is contained in:
Paolo Tranquilli
2025-02-25 13:21:28 +01:00
parent 6089a75262
commit 1bcc6ddb32
11 changed files with 48 additions and 44 deletions

View File

@@ -124,7 +124,7 @@ impl LogWriter {
match std::fs::OpenOptions::new()
.create(true)
.append(true)
.write(true)
.open(path)
{
Err(e) => {

View File

@@ -48,7 +48,7 @@ pub enum DbColumnType {
String,
}
impl<'a> fmt::Display for Case<'a> {
impl fmt::Display for Case<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "case @{}.{} of", &self.name, &self.column)?;
let mut sep = " ";
@@ -60,7 +60,7 @@ impl<'a> fmt::Display for Case<'a> {
}
}
impl<'a> fmt::Display for Table<'a> {
impl fmt::Display for Table<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(keyset) = &self.keysets {
write!(f, "#keyset[")?;
@@ -102,7 +102,7 @@ impl<'a> fmt::Display for Table<'a> {
}
}
impl<'a> fmt::Display for Union<'a> {
impl fmt::Display for Union<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{} = ", self.name)?;
let mut first = true;

View File

@@ -8,7 +8,7 @@ pub enum TopLevel<'a> {
Module(Module<'a>),
}
impl<'a> fmt::Display for TopLevel<'a> {
impl fmt::Display for TopLevel<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
TopLevel::Import(imp) => write!(f, "{}", imp),
@@ -24,7 +24,7 @@ pub struct Import<'a> {
pub alias: Option<&'a str>,
}
impl<'a> fmt::Display for Import<'a> {
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 {
@@ -43,7 +43,7 @@ pub struct Class<'a> {
pub predicates: Vec<Predicate<'a>>,
}
impl<'a> fmt::Display for 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)?;
@@ -93,7 +93,7 @@ pub struct Module<'a> {
pub body: Vec<TopLevel<'a>>,
}
impl<'a> fmt::Display for 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)?;
@@ -122,7 +122,7 @@ pub enum Type<'a> {
Normal(&'a str),
}
impl<'a> fmt::Display for Type<'a> {
impl fmt::Display for Type<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Type::Int => write!(f, "int"),
@@ -152,7 +152,7 @@ pub enum Expression<'a> {
},
}
impl<'a> fmt::Display for Expression<'a> {
impl fmt::Display for Expression<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expression::Var(x) => write!(f, "{}", x),
@@ -246,7 +246,7 @@ pub struct Predicate<'a> {
pub body: Expression<'a>,
}
impl<'a> fmt::Display for 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)?;
@@ -280,7 +280,7 @@ pub struct FormalParameter<'a> {
pub param_type: Type<'a>,
}
impl<'a> fmt::Display for FormalParameter<'a> {
impl fmt::Display for FormalParameter<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {}", self.param_type, self.name)
}

View File

@@ -25,6 +25,12 @@ pub struct Writer {
location_labels: std::collections::HashMap<Location, Label>,
}
impl Default for Writer {
fn default() -> Self {
Self::new()
}
}
impl Writer {
pub fn new() -> Writer {
Writer {
@@ -306,9 +312,9 @@ impl Compression {
#[test]
fn limit_string_test() {
assert_eq!("hello", limit_string(&"hello world".to_owned(), 5));
assert_eq!("hi ☹", limit_string(&"hi ☹☹".to_owned(), 6));
assert_eq!("hi ", limit_string(&"hi ☹☹".to_owned(), 5));
assert_eq!("hello", limit_string("hello world", 5));
assert_eq!("hi ☹", limit_string("hi ☹☹", 6));
assert_eq!("hi ", limit_string("hi ☹☹", 5));
}
#[test]

View File

@@ -28,7 +28,7 @@ pub fn create_source_dir(files: Vec<(&'static str, &'static str)>) -> SourceArch
let path = source_archive_dir.join(filename);
let mut file = File::create(&path).unwrap();
file.write_all(contents.as_bytes()).unwrap();
file_paths.push(PathBuf::from(path));
file_paths.push(path);
}
let file_list = {
@@ -69,5 +69,5 @@ pub fn expect_trap_file(root_dir: &Path, filename: &str) {
fn create_dir(root: &Path, path: impl AsRef<Path>) -> PathBuf {
let full_path = root.join(path);
std::fs::create_dir_all(&full_path).expect("Failed to create directory");
full_path.into()
full_path
}

View File

@@ -1,7 +1,6 @@
use codeql_extractor::extractor::simple;
use codeql_extractor::trap;
use tree_sitter_ql;
mod common;
use common::{SourceArchive, create_source_dir, expect_trap_file};

View File

@@ -1,6 +1,5 @@
use codeql_extractor::extractor::simple;
use codeql_extractor::trap;
use tree_sitter_ql;
mod common;
use common::{SourceArchive, create_source_dir, expect_trap_file};