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

Configured golangci-lint #51

Merged
merged 6 commits into from
Sep 14, 2021
Merged

Configured golangci-lint #51

merged 6 commits into from
Sep 14, 2021

Conversation

palczyn
Copy link
Contributor

@palczyn palczyn commented Sep 6, 2021

Issue: KNTK-192

@danielfurman
Copy link
Contributor

Please squash the commits

@danielfurman
Copy link
Contributor

@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/

mmac-m3a
mmac-m3a previously approved these changes Sep 8, 2021
Copy link
Contributor

@mmac-m3a mmac-m3a left a 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
Copy link
Contributor

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 ;-).

Copy link
Contributor

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

@mmac-m3a
Copy link
Contributor

mmac-m3a commented Sep 8, 2021

Waiting for @Fenthick to approve before merging.

Copy link
Contributor

@danielfurman danielfurman left a 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).

.golangci.yml Outdated Show resolved Hide resolved
.golangci.yml Outdated Show resolved Hide resolved
.golangci.yml Outdated Show resolved Hide resolved
.golangci.yml Outdated Show resolved Hide resolved
.golangci.yml Outdated Show resolved Hide resolved
apiv6/kentikapi/client_integration_test.go Outdated Show resolved Hide resolved
apiv6/kentikapi/httputil/httputil_test.go Outdated Show resolved Hide resolved
apiv6/kentikapi/httputil/httputil_test.go Outdated Show resolved Hide resolved
apiv6/kentikapi/httputil/httputil_test.go Outdated Show resolved Hide resolved
apiv6/kentikapi/httputil/httputil_test.go Outdated Show resolved Hide resolved
apiv6/examples/synthetics/mesh_test/metrics_matrix.go Outdated Show resolved Hide resolved
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// LogPayloads enables logging of request and response api_payloads.
// LogPayloads enables logging of request and response payloads.

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Routes are a collection of defined api api_endpoints
// Routes are a collection of defined api endpoints

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Routes are a collection of defined api api_endpoints
// Routes are a collection of defined api endpoints

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@danielfurman danielfurman left a 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
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will.

Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

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
Copy link
Contributor

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

DeviceSNMNPIP *string
DeviceSNMPCommunity *string
MinimizeSNMP *bool
DeviceBGPType *DeviceBGPType // Note: for DeviceBGPType = DeviceBGPTypeDevice,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto: put comment above

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

@@ -1,3 +1,4 @@
//nolint:dupl
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

@@ -1,3 +1,4 @@
//nolint:dupl
Copy link
Contributor

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

Copy link
Contributor

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,
Copy link
Contributor

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).

https://golangci-lint.run/usage/false-positives/

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

@palczyn
Copy link
Contributor Author

palczyn commented Sep 13, 2021

@mmac-m3a Daniel approved the changes. Can you approve too, because your review got cancelled after the first push with corrections.

Copy link
Contributor

@mmac-m3a mmac-m3a left a 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),
Copy link
Contributor

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?

Copy link
Contributor Author

@palczyn palczyn Sep 14, 2021

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@mmac-m3a mmac-m3a merged commit df5c436 into kentik:master Sep 14, 2021
@palczyn
Copy link
Contributor Author

palczyn commented Sep 14, 2021

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.

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