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

Introduce golangci-lint and fix findings #821

Merged
merged 4 commits into from
Oct 11, 2024
Merged

Conversation

oxzi
Copy link
Member

@oxzi oxzi commented Oct 4, 2024

First, the same GitHub Action used in the icinga-go-library was added to the Go workflow.

Then, the findings were addressed. In general, these were mostly missing return check - when being unused anyway -, potential overflows for integer type conversions, and SHA1 warnings.

If applicable, the code was slightly modified to perform the necessary checks. Sometimes the linter has detected the checks. Sometimes not and a linter comment was added.

@oxzi oxzi added enhancement New feature or request github_actions Pull requests that update GitHub Actions code labels Oct 4, 2024
@oxzi oxzi requested a review from lippserd October 4, 2024 13:57
@cla-bot cla-bot bot added the cla/signed label Oct 4, 2024
Copy link
Member

@lippserd lippserd left a comment

Choose a reason for hiding this comment

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

In addition to the requested changes, I would split the commits, e.g.

  • GitHub Action
  • Ignore errors explicitly
  • Weak SHA1
  • Int conversions

cmd/icingadb-migrate/main.go Outdated Show resolved Hide resolved
pkg/icingadb/types/comment_type.go Outdated Show resolved Hide resolved
@@ -5,6 +5,7 @@ import (
"encoding"
"github.com/icinga/icinga-go-library/types"
"github.com/pkg/errors"
"math"
Copy link
Member

Choose a reason for hiding this comment

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

notification_type does not have UnmarshalJSON() like the other types and I'm not quite sure whether that's intended. Maybe we should streamline all the types so the changes here aren't necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

I asked myself the same, but as it implements encoding.TextUnmarshaler, Go's JSON unmarshaller is also happy.

Otherwise, if the value implements encoding.TextUnmarshaler and the input is a JSON quoted string, Unmarshal calls encoding.TextUnmarshaler.UnmarshalText with the unquoted form of the string.

pkg/icingadb/delta_test.go Outdated Show resolved Hide resolved
pkg/icingadb/history/retention.go Outdated Show resolved Hide resolved
@oxzi oxzi force-pushed the golangci-lint-init-and-fix branch from b451873 to da13cbd Compare October 8, 2024 07:29
@oxzi
Copy link
Member Author

oxzi commented Oct 8, 2024

@lippserd: Thanks for your comment. I have addressed the changes or wrote rationales above.

The commit was also split, as you suggested, just with the GitHub Action commit being the last, as otherwise - when checking the CI for each commit independently - there would be failures before these were addressed.

@oxzi oxzi requested a review from lippserd October 8, 2024 07:32
@oxzi oxzi force-pushed the golangci-lint-init-and-fix branch 2 times, most recently from 6195249 to 1cd597b Compare October 8, 2024 08:46
@oxzi oxzi requested a review from julianbrost October 8, 2024 08:48
@oxzi oxzi force-pushed the golangci-lint-init-and-fix branch from 1cd597b to f3fdc16 Compare October 8, 2024 12:36
lippserd
lippserd previously approved these changes Oct 8, 2024
cmd/icingadb-migrate/convert.go Outdated Show resolved Hide resolved
pkg/icingadb/cleanup.go Outdated Show resolved Hide resolved
pkg/icingadb/history/retention.go Outdated Show resolved Hide resolved
pkg/icingadb/types/notification_type.go Outdated Show resolved Hide resolved
@oxzi oxzi force-pushed the golangci-lint-init-and-fix branch from f3fdc16 to 65cdadf Compare October 9, 2024 09:05
@oxzi oxzi requested review from julianbrost and lippserd October 9, 2024 09:05
@oxzi oxzi force-pushed the golangci-lint-init-and-fix branch from 65cdadf to 07ad635 Compare October 9, 2024 09:22
cmd/icingadb-migrate/convert.go Outdated Show resolved Hide resolved
pkg/icingadb/types/notification_type.go Outdated Show resolved Hide resolved
pkg/icingadb/history/retention.go Outdated Show resolved Hide resolved
@oxzi oxzi force-pushed the golangci-lint-init-and-fix branch 2 times, most recently from a778e5b to a11ba1b Compare October 10, 2024 08:57
oxzi added a commit that referenced this pull request Oct 10, 2024
As discussed in #821, allowing huge retention values - as the type
uint64 allows - may result in overflows. Especially Go's time.AddDate()
method silently overflows for huge values, resulting in unexpected
comparison times.

> $ ./icingadb --config <(echo 'retention: {history-days: -1}')
> can't parse YAML file /proc/self/fd/11: cannot unmarshal -1 into Go value of type uint16 ( overflow )
>
> $ ./icingadb --config <(echo 'retention: {history-days: -100000}')
> can't parse YAML file /proc/self/fd/11: cannot unmarshal -100000 into Go value of type uint16 ( overflow )
@oxzi oxzi requested a review from julianbrost October 10, 2024 09:09
oxzi added a commit that referenced this pull request Oct 10, 2024
As discussed in #821, allowing huge retention values - as the type
uint64 allows - may result in overflows. Especially Go's time.AddDate()
method silently overflows for huge values, resulting in unexpected
comparison times.

> $ ./icingadb --config <(echo 'retention: {history-days: -1}')
> can't parse YAML file /proc/self/fd/11: cannot unmarshal -1 into Go value of type uint16 ( overflow )
>
> $ ./icingadb --config <(echo 'retention: {history-days: 100000}')
> can't parse YAML file /proc/self/fd/11: cannot unmarshal 100000 into Go value of type uint16 ( overflow )
@oxzi oxzi force-pushed the golangci-lint-init-and-fix branch from a11ba1b to 5ede004 Compare October 10, 2024 11:59
oxzi added 2 commits October 11, 2024 09:53
The same GitHub Action already used in the icinga-go-library was added
to the Go workflow.
@oxzi oxzi force-pushed the golangci-lint-init-and-fix branch from 5ede004 to 14d4070 Compare October 11, 2024 07:53
@oxzi oxzi requested a review from julianbrost October 11, 2024 07:55
@lippserd lippserd merged commit df079b1 into main Oct 11, 2024
32 checks passed
@lippserd lippserd deleted the golangci-lint-init-and-fix branch October 11, 2024 09:05
@oxzi oxzi added this to the 1.2.1 milestone Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed enhancement New feature or request github_actions Pull requests that update GitHub Actions code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants