Skip to content

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

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:map
Aug 19, 2022
Merged

lint: add a linter to prohibit map[...]bool in favor of map[...]struct{}#85689
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:map

Conversation

@yuzefovich
Copy link
Copy Markdown
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
Copy Markdown
Member

This change is Reviewable

@yuzefovich
Copy link
Copy Markdown
Member Author

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

@michae2
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Add an opt-out to disable the linter.

TFTRs!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 19, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
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