feat(vet): allow vet to lint anonymous parameter names#4469
Open
JasonDav wants to merge 6 commits into
Open
Conversation
Regenerated internal/vet/vet.pb.go via buf generate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Test currently fails because vetQuery does not yet populate the new Parameter.name field, so named params are wrongly flagged as anonymous. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Anonymous parameters have an empty name, enabling lint rules such as query.params.exists(p, p.name == ""). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allow vet to check for empty Parameter names
sqlc vetlets you write CEL lint rules against your queries, but today the only information exposed about a query parameter is its position (number):That makes it impossible to write a rule about anonymous parameters — parameters sqlc couldn't derive a name for, which it renders in generated code with names Column1, Column2, etc in the golang output.
Anonymous parameters mean ugly and borderline unreadable for large queries hence large param lists.
In this case we force engineers to go back and name them so that the Param structs properties are readable.
Catching them today requires a manual review pass; there's no way to fail
sqlc veton them.This PR exposes the parameter's
nameto vet rules so you can lint for this yourself.What this enables
Given a query whose parameter sqlc can't name:
sqlc vetnow fails:Naming the parameter clears it:
Backward compatibility
Purely additive.
nameis a new optional proto field; existing vet rules and configs are unaffected, and the field defaults to""for any parameter without a column.Test plan
go build ./...go test ./internal/endtoend/ -run 'TestReplay/.*/vet_'— passes (all vet replay cases, both new cases onbaseandmanaged-db)vetexits 1 with the violation; named param → exits 0.