Skip to content

Commit 2974a67

Browse files
authored
clippy fix (#231)
* clippy fix * fmt
1 parent 143bb7b commit 2974a67

File tree

13 files changed

+37
-39
lines changed

13 files changed

+37
-39
lines changed

src/common/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl Config {
132132

133133
/// Retrieves the configuration required for generating typescript interface
134134
/// If there is CLI_ARGS.generate_types set already, it would prioritise using CLI_ARGS
135+
#[allow(deprecated)]
135136
fn generate_types_config(file_config_path: &PathBuf) -> Option<GenerateTypesConfig> {
136137
let file_based_config = fs::read_to_string(file_config_path);
137138
let file_based_config = &file_based_config.map(|f| serde_json::from_str::<SqlxConfig>(f.as_str()).unwrap());

src/common/logger.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ macro_rules! warning {
7373

7474
pub(crate) use warning;
7575

76+
#[allow(unused_macros)]
7677
macro_rules! error {
7778
($arg:tt) => ({
7879
use crate::common::lazy::CONFIG;
@@ -98,4 +99,5 @@ macro_rules! error {
9899
});
99100
}
100101

102+
#[allow(unused_imports)]
101103
pub(crate) use error;

src/parser/js_parser.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ use crate::parser::decl::{process_decl, process_default_decl};
1515
use crate::parser::import::find_sqlx_import_alias;
1616
use crate::parser::tag::get_sql_from_expr;
1717
use swc_ecma_ast::{Key, ModuleDecl, ModuleItem, Stmt};
18-
use swc_ecma_parser::TsConfig;
18+
use swc_ecma_parser::TsSyntax;
1919
use swc_ecma_parser::{lexer::Lexer, Parser, Syntax};
2020

21-
fn insert_or_append_sqls(sqls_container: &mut HashMap<PathBuf, Vec<SQL>>, sqls: &Vec<SQL>, file_path: &PathBuf) {
21+
fn insert_or_append_sqls(sqls_container: &mut HashMap<PathBuf, Vec<SQL>>, sqls: &[SQL], file_path: &PathBuf) {
2222
if sqls_container.contains_key(&*file_path.clone()) {
2323
let mut value = sqls_container.get(file_path).unwrap().clone();
24-
value.extend(sqls.clone());
24+
value.extend(sqls.to_owned());
2525
sqls_container.insert(file_path.clone(), (*value.to_owned()).to_owned());
2626
} else {
27-
sqls_container.insert(file_path.clone(), sqls.clone());
27+
sqls_container.insert(file_path.clone(), sqls.to_owned());
2828
}
2929
}
3030

@@ -135,15 +135,15 @@ pub fn parse_js_file(path: &PathBuf) -> Result<(HashMap<PathBuf, Vec<SQL>>, Hand
135135

136136
let file_path = path.as_os_str().to_str().unwrap().to_string();
137137
let fm = cm.new_source_file(Rc::new(FileName::Custom(file_path)), contents);
138-
let ts_config: TsConfig = TsConfig {
138+
let ts_syntax = TsSyntax {
139139
tsx: false,
140140
decorators: true,
141141
dts: false,
142142
no_early_errors: false,
143143
disallow_ambiguous_jsx_like: false,
144144
};
145145
let lexer = Lexer::new(
146-
Syntax::Typescript(ts_config),
146+
Syntax::Typescript(ts_syntax),
147147
Default::default(),
148148
StringInput::from(&*fm),
149149
None,

src/parser/sql_parser.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use color_eyre::eyre::Result;
33
use regex::Regex;
44
use std::collections::HashMap;
55
use std::fs;
6-
use std::path::PathBuf;
6+
use std::path::{Path, PathBuf};
77
use swc_common::{
88
errors::{ColorConfig, Handler},
99
sync::Lrc,
@@ -27,7 +27,7 @@ pub fn parse_sql_file(path: &PathBuf) -> Result<(HashMap<PathBuf, Vec<SQL>>, Han
2727

2828
/// Extract SQL queries from raw SQL file content
2929
/// Supports multiple queries separated by semicolons and annotations
30-
fn extract_sql_queries_from_file(content: &str, file_path: &PathBuf) -> Result<Vec<SQL>> {
30+
fn extract_sql_queries_from_file(content: &str, file_path: &Path) -> Result<Vec<SQL>> {
3131
let mut queries = Vec::new();
3232

3333
// Split content by semicolons to handle multiple queries
@@ -42,7 +42,7 @@ fn extract_sql_queries_from_file(content: &str, file_path: &PathBuf) -> Result<V
4242
}
4343

4444
// Extract annotations and clean query
45-
let (query_name, db_connection, cleaned_query) = extract_annotations_from_sql(trimmed_block);
45+
let (query_name, _db_connection, cleaned_query) = extract_annotations_from_sql(trimmed_block);
4646

4747
// Skip if no actual SQL content after cleaning
4848
if cleaned_query.trim().is_empty() {
@@ -191,8 +191,8 @@ fn extract_annotations_from_sql(content: &str) -> (Option<String>, Option<String
191191
}
192192

193193
// Check for name annotation in comments
194-
if trimmed_line.starts_with("--") {
195-
let comment_content = &trimmed_line[2..].trim();
194+
if let Some(stripped) = trimmed_line.strip_prefix("--") {
195+
let comment_content = &stripped.trim();
196196

197197
if let Some(captures) = name_re.captures(comment_content) {
198198
query_name = Some(captures.get(1).unwrap().as_str().trim().to_string());
@@ -232,7 +232,7 @@ fn extract_annotations_from_sql(content: &str) -> (Option<String>, Option<String
232232
}
233233

234234
/// Generate a default query name from file path and index
235-
fn generate_default_query_name(file_path: &PathBuf, index: usize) -> Option<String> {
235+
fn generate_default_query_name(file_path: &Path, index: usize) -> Option<String> {
236236
let file_stem = file_path.file_stem()?.to_str()?;
237237

238238
// Convert to camelCase and add index if multiple queries

src/ts_generator/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum TsGeneratorError {
2323
#[error("[E009] When translating a function in a SELECT clause, you must provide an alias - query : `{0}`")]
2424
FunctionWithoutAliasInSelectClause(String),
2525
#[error("[E010] Unknown function detected while processing a SELECT clause - query: `{0}`")]
26+
#[allow(dead_code)]
2627
FunctionUnknown(String),
2728
// Errors while handling FROM statement
2829
#[error("[E012] Failed to handle a from statement without the `FROM` keyword - query: `{0}`")]

src/ts_generator/generator.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use std::fs::OpenOptions;
22
use std::io::Write;
3-
use std::{
4-
fs,
5-
path::{Path, PathBuf},
6-
};
3+
use std::{fs, path::Path};
74

85
use super::annotations::extract_param_annotations;
96

@@ -52,7 +49,7 @@ pub fn get_query_name(sql: &SQL) -> Result<String> {
5249
}
5350

5451
/// Write colocated Type definition file next to the TS source code
55-
pub fn write_colocated_ts_file(file_path: &PathBuf, sqls_to_write: String) -> Result<()> {
52+
pub fn write_colocated_ts_file(file_path: &Path, sqls_to_write: String) -> Result<()> {
5653
let path = file_path.parent().unwrap();
5754
let file = file_path.file_stem().unwrap();
5855
let file_name = file.to_str().unwrap();

src/ts_generator/sql_parser/expressions/translate_expr.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,6 @@ pub async fn translate_expr(
482482
root: _,
483483
access_chain: _,
484484
} => ts_query.insert_result(alias, &[TsFieldType::Any], is_selection, false, expr_for_logging),
485-
// JsonAccess handles semi-structured data access (e.g., Snowflake VARIANT type)
486-
Expr::JsonAccess { value: _, path: _ } => {
487-
ts_query.insert_result(alias, &[TsFieldType::Any], is_selection, false, expr_for_logging)
488-
}
489485
Expr::Interval(_) => ts_query.insert_result(alias, &[TsFieldType::Number], is_selection, false, expr_for_logging),
490486
Expr::MatchAgainst {
491487
columns: _,

src/ts_generator/sql_parser/expressions/translate_table_with_joins.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::ts_generator::sql_parser::quoted_strings::*;
33
use color_eyre::eyre::Result;
44
use sqlparser::ast::{Assignment, AssignmentTarget, Expr, Join, SelectItem, TableFactor, TableWithJoins};
55

6-
pub fn get_default_table(table_with_joins: &Vec<TableWithJoins>) -> String {
6+
pub fn get_default_table(table_with_joins: &[TableWithJoins]) -> String {
77
table_with_joins
88
.first()
99
.and_then(|x| match &x.relation {
@@ -25,8 +25,8 @@ pub fn get_default_table(table_with_joins: &Vec<TableWithJoins>) -> String {
2525
}
2626

2727
pub fn find_table_name_from_identifier(
28-
table_with_joins: &Vec<TableWithJoins>,
29-
identifiers: &Vec<String>, // can be the actual identifier or an alias
28+
table_with_joins: &[TableWithJoins],
29+
identifiers: &[String], // can be the actual identifier or an alias
3030
) -> Result<String, TsGeneratorError> {
3131
let left = identifiers
3232
.first()
@@ -128,11 +128,11 @@ pub fn translate_table_from_expr(
128128
Expr::Identifier(_) => Ok(get_default_table(table_with_joins)),
129129
Expr::CompoundIdentifier(compound_identifier) => {
130130
// Assumes that [0] of the compound identifiers is the alias that points to the table
131-
let identifiers = &compound_identifier
131+
let identifiers: Vec<String> = compound_identifier
132132
.iter()
133133
.map(|x| DisplayIndent(x).to_string())
134134
.collect();
135-
find_table_name_from_identifier(table_with_joins, identifiers)
135+
find_table_name_from_identifier(table_with_joins, &identifiers)
136136
}
137137
_ => Err(TsGeneratorError::UnknownErrorWhileProcessingTableWithJoins(
138138
expr.to_string(),
@@ -141,7 +141,7 @@ pub fn translate_table_from_expr(
141141
}
142142

143143
pub fn translate_table_from_assignments(
144-
table_with_joins: &Vec<TableWithJoins>,
144+
table_with_joins: &[TableWithJoins],
145145
assignment: &Assignment,
146146
) -> Result<String, TsGeneratorError> {
147147
// In sqlparser 0.59.0, Assignment.id was replaced with Assignment.target
@@ -158,7 +158,7 @@ pub fn translate_table_from_assignments(
158158
match first_part {
159159
Some(part) => {
160160
if let Some(ident) = part.as_ident() {
161-
find_table_name_from_identifier(table_with_joins, &vec![ident.value.to_string()])
161+
find_table_name_from_identifier(table_with_joins, &[ident.value.to_string()])
162162
} else {
163163
// If it's a function-based name, use default table
164164
Ok(get_default_table(table_with_joins))
@@ -192,11 +192,11 @@ pub fn translate_table_with_joins(
192192
match expr {
193193
Expr::CompoundIdentifier(compound_identifier) => {
194194
// Assumes that [0] of the compound identifiers is the alias that points to the table
195-
let identifiers = &compound_identifier
195+
let identifiers: Vec<String> = compound_identifier
196196
.iter()
197197
.map(|x| DisplayIndent(x).to_string())
198198
.collect();
199-
find_table_name_from_identifier(table_with_joins, identifiers)
199+
find_table_name_from_identifier(table_with_joins, &identifiers)
200200
}
201201
_ => Ok(default_table_name),
202202
}
@@ -208,11 +208,11 @@ pub fn translate_table_with_joins(
208208
Ok(default_table_name)
209209
}
210210
Expr::CompoundIdentifier(compound_identifier) => {
211-
let identifiers = &compound_identifier
211+
let identifiers: Vec<String> = compound_identifier
212212
.iter()
213213
.map(|x| DisplayIndent(x).to_string())
214214
.collect();
215-
find_table_name_from_identifier(table_with_joins, identifiers)
215+
find_table_name_from_identifier(table_with_joins, &identifiers)
216216
}
217217
_ => Ok(default_table_name),
218218
},

src/ts_generator/sql_parser/expressions/translate_wildcard_expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ts_generator::types::ts_query::TsQuery;
88
use color_eyre::eyre::Result;
99
use sqlparser::ast::{Join, Select, TableFactor};
1010

11-
pub fn get_all_table_names_from_select(select: &Box<Select>) -> Result<Vec<String>, TsGeneratorError> {
11+
pub fn get_all_table_names_from_select(select: &Select) -> Result<Vec<String>, TsGeneratorError> {
1212
let table_with_joins = select
1313
.from
1414
.first()
@@ -53,7 +53,7 @@ pub fn get_all_table_names_from_select(select: &Box<Select>) -> Result<Vec<Strin
5353
///
5454
/// and it appends result into the hashmap for type generation
5555
pub async fn translate_wildcard_expr(
56-
select: &Box<Select>,
56+
select: &Select,
5757
ts_query: &mut TsQuery,
5858
db_conn: &DBConn,
5959
) -> Result<(), TsGeneratorError> {

src/ts_generator/sql_parser/translate_query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
pub async fn translate_select(
1717
ts_query: &mut TsQuery,
1818
table_with_joins: &Option<Vec<TableWithJoins>>,
19-
select: &Box<Select>,
19+
select: &Select,
2020
db_conn: &DBConn,
2121
alias: Option<&str>,
2222
is_selection: bool,
@@ -41,7 +41,7 @@ pub async fn translate_select(
4141
// Handle all select projects and figure out each field's type
4242
for select_item in projection {
4343
// Determine the default table name within the scope of this select item
44-
let mut table_name_owned: Option<String> = None;
44+
let table_name_owned: Option<String>;
4545
let mut table_name: Option<&str> = None;
4646
if full_table_with_joins.is_some() && !full_table_with_joins.as_ref().unwrap().is_empty() {
4747
table_name_owned = Some(

0 commit comments

Comments
 (0)