Skip to content

Conversation

@andrewmbenton
Copy link
Collaborator

Introducing the @sqlc-vet-disable query annotation, to opt individual queries out of sqlc vet rules, based on #2454.

I'm not sure that printing a message to stdout when skipping a query is ideal, but I didn't want to skip silently or return an error and I couldn't use stderr obviously. If skipping silently is better for now I'm happy to remove that line.

Related to the above, I couldn't figure an easy way to test this new functionality without passing in an output stream separate from stderr where a test would expect the skip message to appear. I can do that, but I wasn't sure about the approach and I'm not a testing expert so maybe there's a better thing we could do. Anyway please advise if there's something I should add regarding testing.

cfg := vetConfig(req)
for i, query := range req.Queries {
if result.Queries[i].Flags[QueryFlagSqlcVetDisable] {
fmt.Printf("Skipping vet rules for query %s", query.Name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think printing to stderr is fine and more correct than printing to stdout. Can we change the format to match error output? Also, if you want to suppress the output by default, you can check to see if debug.Active is true and only print it then.

fmt.Fprintf(c.Stderr, "%s: %s: %s: skipping\n", query.Filename, q.Name, name)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with printing to stderr I think is that's where "normal" vet rule errors are reported, so skipping a rule would trigger a vet fail every time right?

The debug.Active check would suppress that except in cases where someone explicitly opted-in, but I'm still not sure it's the right thing to do.

@andrewmbenton andrewmbenton merged commit dddfe4f into main Jul 18, 2023
@andrewmbenton andrewmbenton deleted the andrew/vet-opt-out branch July 18, 2023 20:20
alfonsodev pushed a commit to ExponentiaTeam/sqlc that referenced this pull request Oct 13, 2025
…qlc-dev#2474)

* feat(vet): Introduce a query annotation to opt out of sqlc vet rules

* Add proper logging, and a test

* Don't remove comments when parsing query annotation metadata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants