feat(lint): lint PL/pgSQL function and DO bodies, report body syntax errors

This commit is contained in:
Hein
2026-10-06 16:44:08 +02:00
parent 96ee6c659b
commit 8dbf0f8fcb
4 changed files with 240 additions and 0 deletions
+31
View File
@@ -123,3 +123,34 @@ func TestCustomEngine(t *testing.T) {
}
_ = diags
}
func TestPlpgsqlBodyLint(t *testing.T) {
src := "create function f() returns void language plpgsql as $$\nbegin\n perform 1;\n select * from t;\nend;\n$$;\n" +
"create function g() returns void language plpgsql as $$\nbegin\n selec 1;\nend;\n$$;\n" +
"create function p() returns void language plpython3u as $$\nselect * from nothing\n$$;\n" +
"do $$ begin select * from t; end $$;\n"
diags, err := lint.New().Check(src, "x.sql")
if err != nil {
t.Fatal(err)
}
var cor001, pl []diagnostics.Diagnostic
for _, d := range diags {
switch d.RuleID {
case "COR001":
cor001 = append(cor001, d)
case "PLPGSQL":
pl = append(pl, d)
}
}
if len(cor001) != 2 || cor001[0].Line != 4 || cor001[0].Col != 10 || cor001[1].Line != 15 {
t.Errorf("COR001 in bodies: %+v", cor001)
}
for _, d := range cor001 {
if d.Fix != nil {
t.Errorf("embedded diagnostic must not carry fixes: %+v", d)
}
}
if len(pl) != 1 || pl[0].Line != 9 || pl[0].Col != 3 {
t.Errorf("PLPGSQL syntax error: %+v", pl)
}
}