Skip to content

Commit ad205b9

Browse files
JasonDavclaude
andcommitted
test(vet): add negative case for anonymous-parameter rule
Companion to vet_anonymous_params: every parameter is named (inferred, sqlc.arg(), and @param), so the no-anonymous-params rule must emit no violations. Guards against false positives / a regression in Parameter.name population. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1d72b0c commit ad205b9

5 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"command": "vet"
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- name: GetByInferredName :one
2+
SELECT id FROM bar
3+
WHERE id = $1;
4+
5+
-- name: GetByArg :one
6+
SELECT id FROM bar
7+
WHERE id = sqlc.arg(target_id);
8+
9+
-- name: GetByAtParam :one
10+
SELECT id FROM bar
11+
WHERE id = @min_id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE bar (id bigserial NOT NULL);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2
2+
sql:
3+
- schema: "schema.sql"
4+
queries: "query.sql"
5+
engine: "postgresql"
6+
gen:
7+
go:
8+
package: "querytest"
9+
out: "db"
10+
rules:
11+
- no-anonymous-params
12+
rules:
13+
- name: no-anonymous-params
14+
message: "query has an anonymous parameter; name it with sqlc.arg() or @name"
15+
rule: |
16+
query.params.exists(p, p.name == "")

internal/endtoend/testdata/vet_anonymous_params_pass/stderr.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)