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

lint: add a linter to prohibit map[...]bool in favor of map[...]struct{} #85689

Merged
merged 1 commit into from
Aug 19, 2022

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Aug 5, 2022

The linter is currently limited to sql/opt/norm package. This commit
was prompted by an article mentioned in the Golang Weekly newsletter.
The rationale is that map[...]struct{} is more efficient, but in some
cases the bool map value is actually desired, so this commit introduces
an opt-out //nolint:maptobool comment.

Release justification: low-risk performance improvement.

Release note: None

@yuzefovich yuzefovich requested a review from a team as a code owner August 5, 2022 20:54
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich
Copy link
Member Author

Curious what people think about such a linter in general @cockroachdb/sql-queries.

@michae2
Copy link
Collaborator

michae2 commented Aug 8, 2022

I'm generally in favor. As you say there are cases where the trinary logic of map[...]bool is actually needed, so it would be nice to have some kind of "nolint" comment or something.

Copy link
Collaborator

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)

Copy link
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @yuzefovich)

The linter is currently limited to `sql/opt/norm` package. This commit
was prompted by an article mentioned in the Golang Weekly newsletter.
The rationale is that `map[...]struct{}` is more efficient, but in some
cases the bool map value is actually desired, so this commit introduces
an opt-out `//nolint:maptobool` comment.

Release justification: low-risk performance improvement.

Release note: None
@yuzefovich
Copy link
Member Author

Add an opt-out to disable the linter.

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Aug 19, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Aug 19, 2022

Build succeeded:

@craig craig bot merged commit 677ef2c into cockroachdb:master Aug 19, 2022
@yuzefovich yuzefovich deleted the map branch August 19, 2022 18:30
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.

4 participants