Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 18, 2023

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.

@@ -299,6 +299,10 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
req := codeGenRequest(result, combo)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants