-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
There was a problem hiding this 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
@@ -5,6 +5,7 @@ import ( | |||
"encoding" | |||
"github.com/icinga/icinga-go-library/types" | |||
"github.com/pkg/errors" | |||
"math" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
b451873
to
da13cbd
Compare
@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. |
6195249
to
1cd597b
Compare
1cd597b
to
f3fdc16
Compare
f3fdc16
to
65cdadf
Compare
65cdadf
to
07ad635
Compare
a778e5b
to
a11ba1b
Compare
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 )
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 )
a11ba1b
to
5ede004
Compare
The same GitHub Action already used in the icinga-go-library was added to the Go workflow.
5ede004
to
14d4070
Compare
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.