Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Exorcise golanci-lint errors #10949

Merged
merged 8 commits into from
May 29, 2020
Merged

Exorcise golanci-lint errors #10949

merged 8 commits into from
May 29, 2020

Conversation

daxmc99
Copy link
Contributor

@daxmc99 daxmc99 commented May 23, 2020

Fixes https://github.com/sourcegraph/sourcegraph/issues/10915

May still need no-lint comments to address go sec file permission errors

@daxmc99 daxmc99 requested a review from emidoots as a code owner May 23, 2020 22:58
@daxmc99 daxmc99 requested a review from a team May 23, 2020 22:58
@daxmc99 daxmc99 changed the title Exercise golanci-lint errors Exorcise golanci-lint errors May 23, 2020
if err := o.validate(); err != nil {
return fmt.Errorf("observable %q: %v", o.Name, err)
for i := range r {
if err := r[i].validate(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Whoah wait is this really a rule?

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 personally prefer using values instead of pointers where I can but here r is so big golangci-lint complains about the copying.

Copy link
Member

Choose a reason for hiding this comment

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

Can we just get golangci-lint to ignore these "errors" instead?

They definitely make sense where performance is critical, but here code readability is more important IMO than performance and not using pointers makes it completely clear that "these are not mutable pointer values"

@daxmc99
Copy link
Contributor Author

daxmc99 commented May 24, 2020

See golang/lint#210 for unexported lint

I feel like the correct way to do this is to use an interface and create a private method that makes that interface unimplementable...
Or it can just be made Exportable

@daxmc99
Copy link
Contributor Author

daxmc99 commented May 24, 2020

I think the gsec lints need to be ignored, grafana and prometheus configs needs to be read-able and editable by user 476 (in grafana's case)
https://github.com/grafana/grafana/blob/master/Dockerfile#L39

@@ -189,8 +189,8 @@ type Observable struct {
//
PossibleSolutions string

// PanelOptions describes some options for how to render the metric in the Grafana panel.
PanelOptions panelOptions
// NewPanelOptions describes some options for how to render the metric in the Grafana panel.
Copy link
Member

Choose a reason for hiding this comment

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

This looks wrong, it no longer starts with the field name. I am surprised the linter didn't complain about this at all.

Suggested change
// NewPanelOptions describes some options for how to render the metric in the Grafana panel.
// PanelOptions describes some options for how to render the metric in the Grafana panel.

if err := o.validate(); err != nil {
return fmt.Errorf("observable %q: %v", o.Name, err)
for i := range r {
if err := r[i].validate(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Can we just get golangci-lint to ignore these "errors" instead?

They definitely make sense where performance is critical, but here code readability is more important IMO than performance and not using pointers makes it completely clear that "these are not mutable pointer values"

}

func (o Observable) validate() error {
func (o *Observable) validate() error {
Copy link
Member

Choose a reason for hiding this comment

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

Can we make it not complain about the pointers here instead? See my comment in https://github.com/sourcegraph/sourcegraph/pull/10949/files#r429587283

@daxmc99
Copy link
Contributor Author

daxmc99 commented May 24, 2020

I'm a bit confused how golangci-lint runs. When I run it locally in /Users/dax/work/sourcegraph/monitoring I still some errors related to stylecheck but I don't see them here ¯\(ツ)

@slimsag PTAL, this should address your comments. It looks like this code is mainly used for generating config so I agree we should prioritize readability

@daxmc99 daxmc99 merged commit 8e28d51 into master May 29, 2020
@daxmc99 daxmc99 deleted the dax/linter branch May 29, 2020 23:55
@emidoots emidoots mentioned this pull request May 30, 2020
37 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address golangci-lint complaints about monitoring/generator.go
3 participants