From 8b614a986311812ed169168e5672ff64e0578052 Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Sat, 31 Jan 2026 17:32:42 -0500 Subject: [PATCH 1/2] linter: undo ignoring single stmts in prefer-robust-stmts aka #231 --- crates/squawk_linter/src/ignore.rs | 19 +++++++++++++ .../src/rules/prefer_robust_stmts.rs | 27 ------------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/crates/squawk_linter/src/ignore.rs b/crates/squawk_linter/src/ignore.rs index 2d97dd22..962bcc1f 100644 --- a/crates/squawk_linter/src/ignore.rs +++ b/crates/squawk_linter/src/ignore.rs @@ -301,6 +301,25 @@ create table users ( }, ), }, + Violation { + code: PreferRobustStmts, + message: "Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.", + text_range: 14..31, + help: None, + fix: Some( + Fix { + title: "Insert `if not exists`", + edits: [ + Edit { + text_range: 24..24, + text: Some( + " if not exists", + ), + }, + ], + }, + ), + }, Violation { code: BanCharField, message: "Using `character` is likely a mistake and should almost always be replaced by `text` or `varchar`.", diff --git a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs index 11081130..486d2d2b 100644 --- a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs +++ b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs @@ -19,18 +19,6 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse) { let mut inside_transaction = ctx.settings.assume_in_transaction; let mut constraint_names: HashMap = HashMap::new(); - let mut total_stmts = 0; - for _ in file.stmts() { - total_stmts += 1; - if total_stmts > 1 { - break; - } - } - if total_stmts <= 1 { - // single stmts are fine - return; - } - enum ActionErrorMessage { IfExists, IfNotExists, @@ -512,21 +500,6 @@ CREATE TABLE "core_bar" ( ); } - #[test] - fn ignore_single_stmts_ok() { - // we don't include a placeholder stmt because we're actually checking - // for the single stmt behavior here - let sql = r#" -CREATE INDEX CONCURRENTLY ON "table_name" ("field_name"); - "#; - lint_ok_with( - sql, - LinterSettings { - assume_in_transaction: true, - ..Default::default() - }, - ); - } #[test] fn create_index_concurrently_without_name_ok() { From 596b37b208b740105890d814471234e2110ed56b Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Sat, 31 Jan 2026 17:37:36 -0500 Subject: [PATCH 2/2] lint --- crates/squawk_linter/src/rules/prefer_robust_stmts.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs index 486d2d2b..7233af00 100644 --- a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs +++ b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs @@ -500,7 +500,6 @@ CREATE TABLE "core_bar" ( ); } - #[test] fn create_index_concurrently_without_name_ok() { let sql = r#"