-
Notifications
You must be signed in to change notification settings - Fork 816
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
cmd/sqlc: Add the vet subcommand #2344
Conversation
@@ -24,6 +25,8 @@ require ( | |||
gopkg.in/yaml.v3 v3.0.1 | |||
) | |||
|
|||
require github.com/stoewer/go-strcase v1.2.0 // indirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have ended up in the longer list of indirect dependencies below right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure honestly. I'll make sure to run go mod tidy
as that will put it in the right spot.
msgs := map[string]string{} | ||
|
||
for _, c := range conf.Rules { | ||
if c.Name == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider putting some of this basic validation inside of a shared config parse/validation area? Not sure if config.Validate() would be the right spot, or somewhere else, or maybe this idea just isn't correct if you think each subcommand should be responsible for validating its own "section" of the config (if it has one)?
9889f0d
to
fc53926
Compare
vet
This is a proposal to add a new subcommand that runs queries through a set of lint rules.
Rules
Rules are defined in the configuration file. They consist of a name, message, and an expression. If the expression evaluates to
true
, an error is reported. These expressions are evaluated using cel-go.Each expression has access to a query object, which is defined as the following struct:
This struct would be expanded in the future to include more query information. We may also add information from a running database, such as the result from
EXPLAIN
.Example
While these examples are simplistic, they give you an idea on what types of rules you can write.