-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add new noSelectStar analyzer #42
Conversation
This guards against forwards compatibility issues from adding new columns an old server won't know how to handle. Relates-to: https://mattermost.atlassian.net/browse/MM-62169
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.
LGTM
noSelectStar/testdata/src/a/a.go
Outdated
Select("id", "name", "*") // want `do not use Select with \*: explicitly select the needed columns instead` | ||
|
||
// These should not trigger warnings for Select function | ||
Select("id, 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.
Can we also add a test case like:
query := s.getQueryBuilder().
Select("*").
From("Channels").
Where(sq.Eq{"Id": ids})
to test for completeness?
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.
Good catch: the previous code was entirely incompatible with our actual pattern here. I confess to offloading too much to aider here: I suppose this is analogous to the self-driving car problem where the drivers risk not paying sufficient attention to take over when things don't go right.
I still used aider to fix this, but enhanced the test cases manually.
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.
Good that we have humans to review code 😂
The commit adds a test case for the squirrel builder pattern to verify that the linter catches SELECT * usage even when using method chaining. Specifically: 1. Imported the squirrel package as `sq` 2. Added a test case using `sq.StatementBuilder.PlaceholderFormat(sq.Dollar).Select("*")...` 3. Added an appropriate `want` comment to verify the linter catches the SELECT * usage This ensures the linter works correctly with fluent SQL builder libraries like squirrel.
Summary
This guards against forwards compatibility issues with
SELECT *
.I won't actually enable this in the monorepo until https://mattermost.atlassian.net/browse/MM-62110 is resolved.
Ticket Link
Relates-to: https://mattermost.atlassian.net/browse/MM-62169