Skip to content

Commit dcc7c19

Browse files
committed
fix: resolve all clippy warnings across both crates
- Add #![expect(clippy::print_stdout, clippy::print_stderr)] to CLI binary - Replace .unwrap() on infallible write! to String with let _ = - Use map_or instead of map().unwrap_or() per clippy::map_unwrap_or - Use let...else instead of match-with-early-return - Fix u64-to-usize truncation with try_from - Handle REPL history fallback without expect() - Add #[expect] for safe unwrap after peek in SQL highlighter
1 parent 1dd9a00 commit dcc7c19

4 files changed

Lines changed: 58 additions & 51 deletions

File tree

crates/sqlize-core/src/catalog/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ impl Column {
277277
pub fn api_param_key(&self) -> &str {
278278
self.api_name
279279
.as_ref()
280-
.map(ApiParamName::as_str)
281-
.unwrap_or(self.name.as_str())
280+
.map_or(self.name.as_str(), ApiParamName::as_str)
282281
}
283282
}
284283

crates/sqlize/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#![expect(
2+
clippy::print_stdout,
3+
clippy::print_stderr,
4+
reason = "CLI binary, stdout is the interface"
5+
)]
6+
17
mod mcp;
28
mod repl;
39

crates/sqlize/src/mcp.rs

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,43 @@ impl SqlizeServer {
7272
/// Returns CREATE TABLE DDL with column types and descriptions.
7373
#[tool(name = "get_schema")]
7474
async fn get_schema(&self, Parameters(args): Parameters<GetSchemaArgs>) -> String {
75-
match &args.table {
76-
Some(name) => match self.catalog_set.describe(name) {
77-
Some(ddl) => ddl,
78-
None => {
79-
let available: Vec<String> = self
80-
.catalog_set
81-
.all_tables()
82-
.iter()
83-
.map(|(_, t)| t.name.as_str().to_owned())
84-
.collect();
85-
format!(
86-
"Table '{name}' not found. Available tables:\n{}",
87-
available.join(", ")
88-
)
89-
}
90-
},
91-
None => {
92-
let mut out = String::from(
93-
"Available tables (use get_schema with a table name for full DDL):\n\n",
94-
);
95-
for (_, table) in self.catalog_set.all_tables() {
96-
let required: Vec<_> =
97-
table.required_params().map(|c| c.name.as_str()).collect();
98-
let req = if required.is_empty() {
99-
String::new()
100-
} else {
101-
format!(" required: {}", required.join(", "))
102-
};
103-
out.push_str(&format!(
104-
" {:<30} -- {}{}\n",
105-
table.name,
106-
table
107-
.description
108-
.as_ref()
109-
.map(sqlize_core::catalog::types::Description::as_str)
110-
.unwrap_or(""),
111-
req,
112-
));
113-
}
114-
out
75+
if let Some(name) = &args.table {
76+
if let Some(ddl) = self.catalog_set.describe(name) {
77+
ddl
78+
} else {
79+
let available: Vec<String> = self
80+
.catalog_set
81+
.all_tables()
82+
.iter()
83+
.map(|(_, t)| t.name.as_str().to_owned())
84+
.collect();
85+
format!(
86+
"Table '{name}' not found. Available tables:\n{}",
87+
available.join(", ")
88+
)
11589
}
90+
} else {
91+
let mut out = String::from(
92+
"Available tables (use get_schema with a table name for full DDL):\n\n",
93+
);
94+
for (_, table) in self.catalog_set.all_tables() {
95+
let required: Vec<_> = table.required_params().map(|c| c.name.as_str()).collect();
96+
let req = if required.is_empty() {
97+
String::new()
98+
} else {
99+
format!(" required: {}", required.join(", "))
100+
};
101+
out.push_str(&format!(
102+
" {:<30} -- {}{}\n",
103+
table.name,
104+
table
105+
.description
106+
.as_ref()
107+
.map_or("", sqlize_core::catalog::types::Description::as_str),
108+
req,
109+
));
110+
}
111+
out
116112
}
117113
}
118114

@@ -127,7 +123,7 @@ impl SqlizeServer {
127123
Err(e) => return format!("Error: {e}"),
128124
};
129125

130-
let max = args.max_rows.unwrap_or(100) as usize;
126+
let max = usize::try_from(args.max_rows.unwrap_or(100)).unwrap_or(usize::MAX);
131127
result.rows.truncate(max);
132128

133129
let row_count = result.rows.len();

crates/sqlize/src/repl.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ const SQL_KEYWORDS: &[&str] = &[
231231
struct SqlHighlighter;
232232

233233
impl Highlighter for SqlHighlighter {
234+
#[expect(
235+
clippy::unwrap_used,
236+
reason = "next() after peek() is safe on Peekable"
237+
)]
234238
fn highlight(&self, line: &str, _cursor: usize) -> StyledText {
235239
let mut styled = StyledText::new();
236240
let keyword_style = Style::new().fg(Color::Cyan).bold();
@@ -322,8 +326,7 @@ impl Completer for SqlCompleter {
322326
let before_cursor = &line[..pos];
323327
let word_start = before_cursor
324328
.rfind(|c: char| c.is_ascii_whitespace() || c == ',' || c == '(' || c == ')')
325-
.map(|i| i + 1)
326-
.unwrap_or(0);
329+
.map_or(0, |i| i + 1);
327330

328331
let partial = &before_cursor[word_start..];
329332
if partial.is_empty() {
@@ -430,7 +433,13 @@ pub async fn run(catalog_set: Arc<CatalogSet>, ctx: Arc<QueryEngine>, format: Ou
430433
Ok(h) => h,
431434
Err(e) => {
432435
eprintln!("Warning: could not open history file: {e}");
433-
FileBackedHistory::new(1000).expect("in-memory history initialization failed")
436+
match FileBackedHistory::new(1000) {
437+
Ok(h) => h,
438+
Err(e) => {
439+
eprintln!("Warning: could not create in-memory history: {e}");
440+
return;
441+
}
442+
}
434443
}
435444
};
436445

@@ -545,8 +554,7 @@ fn handle_show_tables(catalog_set: &CatalogSet) {
545554
let desc = table
546555
.description
547556
.as_ref()
548-
.map(sqlize_core::catalog::types::Description::as_str)
549-
.unwrap_or("-");
557+
.map_or("-", sqlize_core::catalog::types::Description::as_str);
550558

551559
if catalog_set.is_multi() {
552560
builder.push_record([
@@ -732,9 +740,7 @@ fn format_value(v: &ScalarValue) -> String {
732740
}
733741

734742
fn term_width() -> usize {
735-
terminal_size::terminal_size()
736-
.map(|(w, _)| w.0 as usize)
737-
.unwrap_or(120)
743+
terminal_size::terminal_size().map_or(120, |(w, _)| w.0 as usize)
738744
}
739745

740746
fn history_path() -> std::path::PathBuf {

0 commit comments

Comments
 (0)