Skip to content

Fix linter golint #2240

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

Merged
merged 4 commits into from
Dec 5, 2019
Merged

Fix linter golint #2240

merged 4 commits into from
Dec 5, 2019

Conversation

camilamacedo86
Copy link
Contributor

@camilamacedo86 camilamacedo86 commented Nov 19, 2019

Closes: #2227

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 19, 2019
@@ -42,14 +42,14 @@ type CSVUpdater interface {
Apply(*olmapiv1alpha1.ClusterServiceVersion) error
}

type updaterStore struct {
type UpdaterStore struct {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we exporting this type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error occurs because of NewUpdaterStore which will return this structure and is used in another place. See

store := NewUpdaterStore()
.

Copy link
Member

Choose a reason for hiding this comment

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

After looking at it, exporting it does make sense now. I'm okay with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joelanford I understand that your only concern with this PR still this point. However, it is used outside then shows that could not be in lower case at all.

So, if you agree and it is ok for you too, I think we could move forward this one and get it merged. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

This is being removed in #2250.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point so, I will ignore this check for we merge this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

H @estroz and @joelanford,

It was ignored as well. So, I think we could safely move forward here.

@camilamacedo86 camilamacedo86 added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Nov 20, 2019
@camilamacedo86 camilamacedo86 changed the title Fix linter golint WIP: Fix linter golint Nov 21, 2019
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 21, 2019
@camilamacedo86 camilamacedo86 changed the title WIP: Fix linter golint Fix linter golint Nov 21, 2019
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 21, 2019
@camilamacedo86
Copy link
Contributor Author

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 21, 2019
Copy link
Member

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

/lgtm

@@ -36,7 +36,7 @@ var (
skipGeneration bool
)

func newAddApiCmd() *cobra.Command {
func newAddAPICmd() *cobra.Command {
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines 39 to 40
// The nolint here is used to hide the warning "func name will be used as new.NewCmd by other packages, and that stutters; consider calling this Cmd"
// which is a false positive.
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 wrap the comment so it's 80 columns per line? At least break up the first one into 2 lines.

@@ -31,7 +31,7 @@ func NewCmd() *cobra.Command {
Short: "Run scorecard tests",
Long: `Runs blackbox scorecard tests on an operator
`,
RunE: scorecard.ScorecardTests,
RunE: scorecard.Tests,
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with this.

Comment on lines 27 to 30
// The nolint is regards to: type name will be used as watch.WatchFlags by other packages, and that stutters; consider calling this Flags (golint)
// todo(camilamacedo86): Note that we decided to not introduce breakchanges to add the linters and it should be done after.
// From @joe: Even though watch.WatchFlags is an internal type, being embedded here means that changing it to watch.Flags is a breaking change
// to AnsibleOperatorFlags, which is exported. So this is a breaking change.
Copy link
Member

Choose a reason for hiding this comment

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

wrap the comments to 80 or so so I don't have to scroll to the right to read.

Comment on lines 31 to 33
var AnsibleDelims = [2]string{"[[", "]]"}
var (
AnsibleDelims = [2]string{"[[", "]]"}
)
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

This isn't the correct fix for the lint error, which was

internal/scaffold/ansible/constants.go:30:1: comment on exported var `AnsibleDelims` should be of the form `AnsibleDelims ...` (golint)

The correct fix is:

// AnsibleDelims is a slice of two strings representing the left and right delimiters for ansible templates. Arrays can't be constants but this should be a constant.
var AnsibleDelims = [2]string{"[[", "]]"}

@@ -42,14 +42,14 @@ type CSVUpdater interface {
Apply(*olmapiv1alpha1.ClusterServiceVersion) error
}

type updaterStore struct {
type UpdaterStore struct {
Copy link
Member

Choose a reason for hiding this comment

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

After looking at it, exporting it does make sense now. I'm okay with this.

Comment on lines 65 to 74
func (store *UpdaterStore) Apply(csv *olmapiv1alpha1.ClusterServiceVersion) error {
updaters := []CSVUpdater{store.installStrategy, store.crds, store.almExamples}
Copy link
Member

Choose a reason for hiding this comment

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

What is the linter complaining about here? -1 I think s is just fine. I use single letters for all of my struct receivers. I agree store is easier to read, but I knew it was the store because of the receiver. It's a very common paradigm. In our broker repo there are 12260 instances of func (a *

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, I see it now. You are simply making it consistent.

@@ -83,10 +83,10 @@ func ToSnake(s string) string {
}
bits := []string{}
n := ""
real_i := -1
iReal := -1
Copy link
Member

Choose a reason for hiding this comment

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

yep I'm surprised underscore variable compiled.

Comment on lines +25 to +27
type ScorecardFormatter interface { //nolint:golint
// todo(camilamacedo86): The no lint here is for pkg/apis/scorecard/formatting.go:25:6: type name will be used as scorecard.ScorecardFormatter by other packages, and that stutters; consider calling this Formatter (golint)
// However, was decided to not move forward with it now in order to not introduce breakchanges with the task to add the linter. We should to do it after.
Copy link
Member

Choose a reason for hiding this comment

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

👍

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 25, 2019
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@openshift-ci-robot openshift-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 25, 2019
@camilamacedo86 camilamacedo86 added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Nov 26, 2019
@camilamacedo86 camilamacedo86 added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Nov 26, 2019
@openshift-bot
Copy link

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Nov 26, 2019
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@camilamacedo86 camilamacedo86 added the lgtm Indicates that a PR is ready to be merged. label Nov 26, 2019
Comment on lines 31 to 33
var AnsibleDelims = [2]string{"[[", "]]"}
var (
AnsibleDelims = [2]string{"[[", "]]"}
)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't the correct fix for the lint error, which was

internal/scaffold/ansible/constants.go:30:1: comment on exported var `AnsibleDelims` should be of the form `AnsibleDelims ...` (golint)

The correct fix is:

// AnsibleDelims is a slice of two strings representing the left and right delimiters for ansible templates. Arrays can't be constants but this should be a constant.
var AnsibleDelims = [2]string{"[[", "]]"}

/*
The nolint is regards to: type name will be used as watch.WatchFlags by other packages, and that stutters; consider calling this Flags (golint)
todo(camilamacedo86): Note that we decided to not introduce breakchanges to add the linters and it should be done after.
From @joe: Even though watch.WatchFlags is an internal type, being embedded here means that changing it to watch.Flags is a breaking change
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
From @joe: Even though watch.WatchFlags is an internal type, being embedded here means that changing it to watch.Flags is a breaking change
From @joelanford: Even though watch.WatchFlags is an internal type, it is embedded in exported types, which means that changing it to watch.Flags is a breaking change.

Then also delete line 31.

@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 2, 2019
/*
* todo(camilamacedo86): remove //nolint:golint after merge of https://github.com/operator-framework/operator-sdk/pull/2250
Skip golint because it will be changed here: https://github.com/operator-framework/operator-sdk/pull/2250
receiver name store should be consistent with previous receiver name s for updaterStore (golint)
Copy link
Member

Choose a reason for hiding this comment

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

This should be fixable by renaming store to s. Is there a reason we aren't doing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the above PR was merged. So, i will be working on it and let you know.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 5, 2019
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

One nit. Other than that, it LGTM.

@@ -97,6 +103,7 @@ type InstallStrategyUpdate struct {
}

func (store *updaterStore) AddRole(yamlDoc []byte) error {

Copy link
Member

Choose a reason for hiding this comment

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

Nit: remove the extraneous new lines that were added in this PR.

@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 5, 2019
@camilamacedo86 camilamacedo86 merged commit 92d78a2 into operator-framework:master Dec 5, 2019
@camilamacedo86 camilamacedo86 deleted the fix-linter-golint branch December 5, 2019 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable golint in the linter and fix issues
6 participants