Skip to content

Commit 0485b85

Browse files
authored
linter: undo ignoring single stmts in prefer-robust-stmts aka #231 (#902)
1 parent ec9733e commit 0485b85

2 files changed

Lines changed: 19 additions & 28 deletions

File tree

crates/squawk_linter/src/ignore.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,25 @@ create table users (
301301
},
302302
),
303303
},
304+
Violation {
305+
code: PreferRobustStmts,
306+
message: "Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.",
307+
text_range: 14..31,
308+
help: None,
309+
fix: Some(
310+
Fix {
311+
title: "Insert `if not exists`",
312+
edits: [
313+
Edit {
314+
text_range: 24..24,
315+
text: Some(
316+
" if not exists",
317+
),
318+
},
319+
],
320+
},
321+
),
322+
},
304323
Violation {
305324
code: BanCharField,
306325
message: "Using `character` is likely a mistake and should almost always be replaced by `text` or `varchar`.",

crates/squawk_linter/src/rules/prefer_robust_stmts.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
1919
let mut inside_transaction = ctx.settings.assume_in_transaction;
2020
let mut constraint_names: HashMap<Identifier, Constraint> = HashMap::new();
2121

22-
let mut total_stmts = 0;
23-
for _ in file.stmts() {
24-
total_stmts += 1;
25-
if total_stmts > 1 {
26-
break;
27-
}
28-
}
29-
if total_stmts <= 1 {
30-
// single stmts are fine
31-
return;
32-
}
33-
3422
enum ActionErrorMessage {
3523
IfExists,
3624
IfNotExists,
@@ -512,22 +500,6 @@ CREATE TABLE "core_bar" (
512500
);
513501
}
514502

515-
#[test]
516-
fn ignore_single_stmts_ok() {
517-
// we don't include a placeholder stmt because we're actually checking
518-
// for the single stmt behavior here
519-
let sql = r#"
520-
CREATE INDEX CONCURRENTLY ON "table_name" ("field_name");
521-
"#;
522-
lint_ok_with(
523-
sql,
524-
LinterSettings {
525-
assume_in_transaction: true,
526-
..Default::default()
527-
},
528-
);
529-
}
530-
531503
#[test]
532504
fn create_index_concurrently_without_name_ok() {
533505
let sql = r#"

0 commit comments

Comments
 (0)