feat(lint): lint code-like dollar-quoted SQL strings

This commit is contained in:
Hein
2026-10-06 16:51:04 +02:00
parent 8dbf0f8fcb
commit 0b26c49931
4 changed files with 152 additions and 1 deletions
+20
View File
@@ -154,3 +154,23 @@ func TestPlpgsqlBodyLint(t *testing.T) {
t.Errorf("PLPGSQL syntax error: %+v", pl)
}
}
func TestEmbeddedDollarSQLLint(t *testing.T) {
src := "create function f() returns void language plpgsql as $$\nbegin\n execute $q$\n select * from t\n $q$;\nend;\n$$;\n" +
"create function s() returns int language sql as $$ select * from u $$;\n" +
"create function p() returns void language plpython3u as $$\nselect * from nothing\n$$;\n" +
"select format($f$select %I from t$f$, 'a');\n"
diags, err := lint.New().Check(src, "x.sql")
if err != nil {
t.Fatal(err)
}
var got [][2]int
for _, d := range diags {
if d.RuleID == "COR001" {
got = append(got, [2]int{d.Line, d.Col})
}
}
if len(got) != 2 || got[0] != [2]int{4, 12} || got[1] != [2]int{8, 59} {
t.Errorf("COR001 positions: %v", got)
}
}