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

Add new noSelectStar analyzer #42

Merged
merged 3 commits into from
Dec 13, 2024
Merged

Add new noSelectStar analyzer #42

merged 3 commits into from
Dec 13, 2024

Conversation

lieut-data
Copy link
Member

@lieut-data lieut-data commented Dec 10, 2024

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

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
@lieut-data lieut-data added the 2: Dev Review Requires review by a core committer label Dec 10, 2024
Copy link
Member

@jespino jespino left a comment

Choose a reason for hiding this comment

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

LGTM

noSelectStar/noSelectStar.go Show resolved Hide resolved
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")
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.
@lieut-data lieut-data added 3: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer labels Dec 13, 2024
@lieut-data lieut-data merged commit 065c05c into new Dec 13, 2024
5 checks passed
@lieut-data lieut-data deleted the add-noSelectStar-check branch December 13, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants