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

[chore] Upgrade golangci-lint, ignore existing int overflow warnings #3420

Merged
merged 18 commits into from
Oct 16, 2024

Conversation

untitaker
Copy link
Contributor

@untitaker untitaker commented Oct 12, 2024

There is a new lint for unchecked int casts. Integer overflows are bad,
but the old code that triggers this lint seems to be perfectly fine.
Instead of disabling the lint entirely for new code as well, grandfather
in existing code. Maybe new code can be written in such a way to avoid
excessive casting.

Also fix a broken link in CONTRIBUTING

tsmethurst and others added 9 commits September 1, 2024 17:35
There is a new lint for unchecked int casts. Integer overflows are bad,
but the old code that triggers this lint seems to be perfectly fine.
Instead of disabling the lint entirely for new code as well, grandfather
in existing code.
@untitaker
Copy link
Contributor Author

oops, this is a duplicate of #3258 -- though that one is stuck. can port over the nolint annotations from there.

@tsmethurst
Copy link
Contributor

Porting over the nolint annotations and math.MaxWhatever checks is probably a good idea 👍

@NyaaaWhatsUpDoc
Copy link
Member

having this linter is a good idea, though replacing api model ints with uints i'm not sure about. the reason that go returns signed integer types for lengths, silces, capacities etc is that a signed integer overflow specifically causes a panic as a negative length is invalid. but an unsigned integer just silently overflows to a valid result which makes hunting down bugs much harder.

if avatar.Size > int64(maxsz) {
text := fmt.Sprintf("media exceeds configured max size: %s", maxsz)
if avatar.Size > maxsz {
text := fmt.Sprintf("media exceeds configured max size: %d", maxsz)
Copy link
Member

Choose a reason for hiding this comment

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

bytesize.Size specifically implements String() for nicer log output, this will only make error responses harder to read by returning a number bytes in the order of millions vs simplified size output.

leaving it as it was ensures we keep that nicer log output both here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll revert those things then. I suggest to change go-bytesize to use the same type as file sizes in the rest of std. this conversion shouldn't be necessary at all if everybody just agrees on a type.

@NyaaaWhatsUpDoc
Copy link
Member

just realized these changes are from the go1.23 PR, but i hadn't gotten around to reading that one yet 😅

given these weren't your changes either myself or @tsmethurst can make them (though totally i'm happy to), if so just let me know :)

@untitaker
Copy link
Contributor Author

np im doing it

@untitaker
Copy link
Contributor Author

this is also ready to review IMO

@tsmethurst
Copy link
Contributor

Hell yeah nice, thanks! I'll take a look tomorrow :)

@tsmethurst tsmethurst merged commit a48cce8 into superseriousbusiness:main Oct 16, 2024
2 checks passed
@tsmethurst
Copy link
Contributor

Squerged, thank you very much!

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.

3 participants