-
Notifications
You must be signed in to change notification settings - Fork 4
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
Configured golangci-lint #51
Conversation
Please squash the commits |
@Opelord Please rename the commit to e.g. Configure golangci-lint and adjust the code to comply Also, take a look: https://chris.beams.io/posts/git-commit/ |
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 hope those linters are worth those 101 mouse clicks :-).
flag.Parse() | ||
return | ||
return address, cloudexport, synthetics |
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.
It is interesting that the code worked before without any value being returned ;-).
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.
It was a naked return: https://tour.golang.org/basics/7 - possible, but unreadable
Waiting for @Fenthick to approve before merging. |
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.
Partially reviewed.
Renaming package names leads to too big diff - it is too hard to review. Please revert package renames (and suppress linter).
apiv6/kentikapi/client.go
Outdated
@@ -32,7 +34,7 @@ type Config struct { | |||
AuthEmail string | |||
AuthToken string | |||
RetryCfg RetryConfig | |||
// LogPayloads enables logging of request and response payloads. | |||
// LogPayloads enables logging of request and response api_payloads. |
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.
// LogPayloads enables logging of request and response api_payloads. | |
// LogPayloads enables logging of request and response payloads. |
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.
Done
@@ -29,7 +30,7 @@ type Route struct { | |||
HandlerFunc http.HandlerFunc | |||
} | |||
|
|||
// Routes are a collection of defined api endpoints | |||
// Routes are a collection of defined api api_endpoints |
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.
// Routes are a collection of defined api api_endpoints | |
// Routes are a collection of defined api endpoints |
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.
Done
@@ -29,7 +30,7 @@ type Route struct { | |||
HandlerFunc http.HandlerFunc | |||
} | |||
|
|||
// Routes are a collection of defined api endpoints | |||
// Routes are a collection of defined api api_endpoints |
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.
// Routes are a collection of defined api api_endpoints | |
// Routes are a collection of defined api endpoints |
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.
Done
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.
Finished
SNMPID *models.ID `json:"snmp_id,string,omitempty" request:"post" response:"get,post,put"` | ||
SNMPSpeed IntAsString `json:"snmp_speed,omitempty"` // caveat, GET returns snmp_speed as string but POST and PUT as int | ||
SNMPID *models.ID `json:"snmp_id,string,omitempty" request:"post" response:"get,post,put"` | ||
SNMPSpeed IntAsString `json:"snmp_speed,omitempty"` // caveat, GET returns snmp_speed as string |
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.
If the comment is too long, put it above the field.
For VRF and VRFID too.
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.
Done
@@ -146,6 +147,7 @@ type queryArrayItemPayload struct { | |||
IsOverlay *bool `json:"isOverlay,omitempty"` | |||
} | |||
|
|||
//nolint:nilerr |
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.
@mateuszmidor Is this intended that the error returned from queryToPayload() function is discarded here? It seems risky to me, because we're silencing possible conversion errors here and the library sends different query payload than user intended.
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.
Error should be passed up the call chain
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.
@Opelord Could you fix that here? It should be straightforward to pass the error up the call stack.
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.
Yes, I will.
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.
Done
Dimension []string `json:"dimension,omitempty"` | ||
FiltersObj *filtersPayload `json:"filters_obj,omitempty"` | ||
SavedFilters []savedFilterPayload `json:"saved_filters,omitempty"` | ||
MatrixBy []string `json:"matrixBy" request:"post"` // matrixBy is required in request even if empty. |
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.
Please put comment above the field
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.
Done
@@ -113,10 +114,11 @@ func (p filtersPayload) ToFilters() (models.Filters, error) { | |||
}, nil | |||
} | |||
|
|||
//nolint:revive // FiltersToPayload could be unexported but filtersToPayload already exists |
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.
We could have filtersToPayload() and filtersPointerToPayload() methods. So this one here would be named filtersToPayload(), because it takes value.
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.
Done
@@ -49,7 +49,8 @@ func (a *AlertingAPI) GetActiveAlerts(ctx context.Context, params models.AlertsQ | |||
return response.ToAlarms(), nil | |||
} | |||
|
|||
func (a *AlertingAPI) GetAlertsHistory(ctx context.Context, params models.AlertsQueryParams) ([]models.HistoricalAlert, error) { | |||
func (a *AlertingAPI) GetAlertsHistory(ctx context.Context, | |||
params models.AlertsQueryParams) ([]models.HistoricalAlert, error) { |
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.
Please put line break after last input argument, so that input arguments and function body are not in line.
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.
Done
@@ -1,4 +1,5 @@ | |||
package api_resources | |||
//nolint:dupl |
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.
Please do not use package-level nolint, if possible
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.
Done
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.
Where was this fixed? I'm, not seeing it.
@@ -1,4 +1,5 @@ | |||
package api_resources | |||
//nolint:dupl |
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.
Please do not use package-level nolint if possible. (Put above duplicating code)
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.
Done
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.
Same here
kentikapi/models/device.go
Outdated
DeviceSNMNPIP *string | ||
DeviceSNMPCommunity *string | ||
MinimizeSNMP *bool | ||
DeviceBGPType *DeviceBGPType // Note: for DeviceBGPType = DeviceBGPTypeDevice, |
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.
Ditto: put comment above
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.
Done
kentikapi/tags_integration_test.go
Outdated
@@ -1,3 +1,4 @@ | |||
//nolint:dupl |
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.
Please put it next to duplicated code
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.
Done
kentikapi/users_integration_test.go
Outdated
@@ -1,3 +1,4 @@ | |||
//nolint:dupl |
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.
Please put it next to duplicated code
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.
Done
.golangci.yml
Outdated
@@ -23,6 +23,14 @@ issues: | |||
- gochecknoglobals | |||
- lll | |||
- gomnd | |||
# tags.go and users.go are called by dupl in entirety. Nolints on package level are not recommended, |
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 wasn't aware that those files are duplicated as a whole. In that case whole file could be excluded. I checked in docs that there are no package-level excludes. So the simplest solution is to put nolint statement in a file (but maybe not above package
statement so that it would not be a package docstring, if possible).
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.
It seems //nolint directive is ignored by godoc.
I will revert the changes to the previous commit as there is also no other way to nolint an entire file in another place.
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.
Done
@mmac-m3a Daniel approved the changes. Can you approve too, because your review got cancelled after the first push with corrections. |
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 cannot look at it anymore ... and definitely don't want to go though 80+ clicks again :-).
... but, please, answer my questions.
@@ -76,7 +77,7 @@ func SavedFilterToPayload(sf models.SavedFilter) savedFilterPayload { | |||
FilterLevel: sf.FilterLevel, | |||
CreatedDate: &sf.CreatedDate, | |||
UpdatedDate: &sf.UpdatedDate, | |||
Filters: FiltersToPayload(sf.Filters), | |||
Filters: filtersToPayload(sf.Filters), |
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.
The logic behind those renamings escapes me. At one place we are changing from (ugly) camelCase
to (little bit less ugly) CamelCase
(e.g. here)... and here it is the other way around. Is this forced by the linters (aren't they fighting each other)? Is this a type-name vs. function-name thing?
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 Golang the difference between CamelCase
and camelCase
is the difference between an exported
and unexported
field, struct or function. (example) It is genereally discouraged to have an exported function (a function that can be used by other packages) return an unexported struct.
Now in this case we had an exported function return an unexported type but the function wasn't used in other packages. So instead of exporting the return I "unexported" (if this is even a word) the function.
In case of RestClient we came to conclusion that because functions returning this struct are used in other packages than the return type should be exported too.
golang/lint#210
@@ -1,4 +1,5 @@ | |||
package api_resources | |||
//nolint:dupl |
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.
Where was this fixed? I'm, not seeing it.
@@ -1,4 +1,5 @@ | |||
package api_resources | |||
//nolint:dupl |
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.
Same here
As for your question here it was solved in this conversation. The problem was that I was supposed to avoid package level nolints. The logic being that it's better to nolint only the block of code that is called by the linter. However in these files the linter highlighted all of their content as a duplicate of the other. I tried to move the exception to the linters configuration file but it hurt clarity of what is actually happening so we decided to move it back. Hence probably the confusion that nothing changed. |
Issue: KNTK-192