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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/operator-sdk/add/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

👍

apiCmd := &cobra.Command{
Use: "api",
Short: "Adds a new api definition under pkg/apis",
Expand Down
2 changes: 1 addition & 1 deletion cmd/operator-sdk/add/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewCmd() *cobra.Command {
Long: "",
}

cmd.AddCommand(newAddApiCmd())
cmd.AddCommand(newAddAPICmd())
cmd.AddCommand(newAddControllerCmd())
cmd.AddCommand(newAddCRDCmd())
return cmd
Expand Down
8 changes: 7 additions & 1 deletion cmd/operator-sdk/new/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

func NewCmd() *cobra.Command {
func NewCmd() *cobra.Command { //nolint:golint
/*
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.
*/
newCmd := &cobra.Command{
Use: "new <project-name>",
Short: "Creates a new operator application",
Expand Down
2 changes: 1 addition & 1 deletion cmd/operator-sdk/scorecard/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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.

}

scorecardCmd.Flags().String(scorecard.ConfigOpt, "", fmt.Sprintf("config file (default is '<project_dir>/%s'; the config file's extension and format can be .yaml, .json, or .toml)", scorecard.DefaultConfigFile))
Expand Down
2 changes: 1 addition & 1 deletion hack/tests/check-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ source ./hack/common.sh
DEV_LINTERS=(
##todo(camilamacedo86): The following checks requires fixes in the code.
##todo(camilamacedo86): they should be enabled and added in the CI
"--enable=golint"
"--enable=gocyclo"
"--enable=lll"
"--enable=gosec" # NOT add this one to CI since was defined that it should be optional for now at least.
Expand Down Expand Up @@ -45,4 +44,5 @@ golangci-lint run --disable-all \
--enable=errcheck \
--enable=dupl \
--enable=unparam \
--enable=golint \
${LINTERS[@]}
8 changes: 7 additions & 1 deletion internal/flags/watch/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ import (

// WatchFlags provides flag for configuration of a controller's reconcile period and for a
// watches.yaml file, which is used to configure dynamic operators (e.g. Ansible and Helm).
type WatchFlags struct {
type WatchFlags struct { //nolint:golint
/*
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 @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.
*/

ReconcilePeriod time.Duration
WatchesFile string
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scaffold/add_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestAddController(t *testing.T) {
r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scaffold/addtoscheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestAddToScheme(t *testing.T) {
r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scaffold/ansible/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ const (
MoleculeTestLocalDir = MoleculeDir + filePathSep + "test-local"
)

// Arrays can't be constants but this should be a constant
// 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{"[[", "]]"}
2 changes: 1 addition & 1 deletion internal/scaffold/controller_kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestControllerKind(t *testing.T) {
r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/scaffold/cr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestCR(t *testing.T) {
r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand All @@ -38,7 +38,7 @@ func TestCR(t *testing.T) {
}

func TestCRCustomSpec(t *testing.T) {
r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/scaffold/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestCRDNonGoProjectDefault(t *testing.T) {
s, buf := setupScaffoldAndWriter()
s.Fs = afero.NewMemMapFs()

r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestCRDNonGoProjectCustom(t *testing.T) {
s, buf := setupScaffoldAndWriter()
s.Fs = afero.NewMemMapFs()

r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scaffold/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestDoc(t *testing.T) {
r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand Down
17 changes: 8 additions & 9 deletions internal/scaffold/helm/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestCreateChart(t *testing.T) {
latestVersion = "1.2.3"
previousVersion = "1.2.0"
nonExistentVersion = "0.0.1"
customApiVersion = "example.com/v1"
customAPIVersion = "example.com/v1"
customKind = "MyApp"
customExpectName = "myapp"
expectDerivedKind = "TestChart"
Expand Down Expand Up @@ -111,9 +111,9 @@ func TestCreateChart(t *testing.T) {
},
{
name: "from scaffold with apiVersion and kind",
apiVersion: customApiVersion,
apiVersion: customAPIVersion,
kind: customKind,
expectResource: mustNewResource(t, customApiVersion, customKind),
expectResource: mustNewResource(t, customAPIVersion, customKind),
expectChartName: customExpectName,
expectChartVersion: "0.1.0",
},
Expand Down Expand Up @@ -148,8 +148,8 @@ func TestCreateChart(t *testing.T) {
{
name: "from repo and name implicit latest with apiVersion",
helmChart: latest.repoAndName,
apiVersion: customApiVersion,
expectResource: mustNewResource(t, customApiVersion, expectDerivedKind),
apiVersion: customAPIVersion,
expectResource: mustNewResource(t, customAPIVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
Expand All @@ -164,9 +164,9 @@ func TestCreateChart(t *testing.T) {
{
name: "from repo and name implicit latest with apiVersion and kind",
helmChart: latest.repoAndName,
apiVersion: customApiVersion,
apiVersion: customAPIVersion,
kind: customKind,
expectResource: mustNewResource(t, customApiVersion, customKind),
expectResource: mustNewResource(t, customAPIVersion, customKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
Expand Down Expand Up @@ -301,10 +301,9 @@ func runTestCase(t *testing.T, testDir string, tc createChartTestCase) {
if tc.expectErr {
assert.Error(t, err)
return
} else {
assert.NoError(t, err)
}

assert.NoError(t, err)
assert.Equal(t, tc.expectResource, resource)
assert.Equal(t, tc.expectChartName, chart.GetMetadata().GetName())
assert.Equal(t, tc.expectChartVersion, chart.GetMetadata().GetVersion())
Expand Down
4 changes: 2 additions & 2 deletions internal/scaffold/olm-catalog/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ func (s *CSV) updateCSVVersions(csv *olmapiv1alpha1.ClusterServiceVersion) error

// updateCSVFromManifestFiles gathers relevant data from generated and
// user-defined manifests and updates csv.
func (g *CSV) updateCSVFromManifests(cfg *CSVConfig, csv *olmapiv1alpha1.ClusterServiceVersion) (err error) {
func (s *CSV) updateCSVFromManifests(cfg *CSVConfig, csv *olmapiv1alpha1.ClusterServiceVersion) (err error) {
paths := append(cfg.CRDCRPaths, cfg.OperatorPath)
paths = append(paths, cfg.RolePaths...)
manifestGVKMap := map[schema.GroupVersionKind][][]byte{}
crGVKSet := map[schema.GroupVersionKind]struct{}{}
for _, path := range paths {
info, err := g.getFS().Stat(path)
info, err := s.getFS().Stat(path)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scaffold/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestRegister(t *testing.T) {
r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scaffold/test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
// test constants describing an app operator project
appProjectName = "app-operator"
appRepo = "github.com/example-inc/" + appProjectName
appApiVersion = "app.example.com/v1alpha1"
appAPIVersion = "app.example.com/v1alpha1"
appKind = "AppService"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/scaffold/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestTypes(t *testing.T) {
r, err := NewResource(appApiVersion, appKind)
r, err := NewResource(appAPIVersion, appKind)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scorecard/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func getPlugins(version string, selector labels.Selector) ([]Plugin, error) {
return plugins, nil
}

func ScorecardTests(cmd *cobra.Command, args []string) error {
func Tests(cmd *cobra.Command, args []string) error {
if err := initConfig(); err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/ansible/paramconv/paramconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.


for i, v := range s {
real_i += 1
iReal++
// treat acronyms as words, eg for JSONData -> JSON is a whole word
nextCaseIsChanged := false
if i+1 < len(s) {
Expand All @@ -96,22 +96,22 @@ func ToSnake(s string) string {
}
}

if real_i > 0 && n[len(n)-1] != '_' && nextCaseIsChanged {
if iReal > 0 && n[len(n)-1] != '_' && nextCaseIsChanged {
// add underscore if next letter case type is changed
if v >= 'A' && v <= 'Z' {
bits = append(bits, strings.ToLower(n))
n = string(v)
real_i = 0
iReal = 0
} else if v >= 'a' && v <= 'z' {
bits = append(bits, strings.ToLower(n+string(v)))
n = ""
real_i = -1
iReal = -1
}
} else if v == ' ' || v == '_' || v == '-' {
// replace spaces/underscores with delimiters
bits = append(bits, strings.ToLower(n))
n = ""
real_i = -1
iReal = -1
} else {
n = n + string(v)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/ansible/runner/internal/inputdir/inputdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func (i *InputDir) Write() error {
// ANSIBLE_INVENTORY takes precedence over our generated hosts file
// so if the envvar is set we don't bother making it, we just copy
// the inventory into our runner directory
ansible_inventory := os.Getenv("ANSIBLE_INVENTORY")
if ansible_inventory == "" {
ansibleInventory := os.Getenv("ANSIBLE_INVENTORY")
if ansibleInventory == "" {
// If ansible-runner is running in a python virtual environment, propagate
// that to ansible.
venv := os.Getenv("VIRTUAL_ENV")
Expand All @@ -151,18 +151,18 @@ func (i *InputDir) Write() error {
return err
}
} else {
fi, err := os.Stat(ansible_inventory)
fi, err := os.Stat(ansibleInventory)
if err != nil {
return err
}
switch mode := fi.Mode(); {
case mode.IsDir():
err = i.copyInventory(ansible_inventory, filepath.Join(i.Path, "inventory"))
err = i.copyInventory(ansibleInventory, filepath.Join(i.Path, "inventory"))
if err != nil {
return err
}
case mode.IsRegular():
err = i.copyInventory(ansible_inventory, filepath.Join(i.Path, "inventory/hosts"))
err = i.copyInventory(ansibleInventory, filepath.Join(i.Path, "inventory/hosts"))
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/scorecard/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
var _ ScorecardFormatter = &scapiv1alpha1.ScorecardOutput{}
var _ ScorecardFormatter = &scapiv1alpha2.ScorecardOutput{}

type ScorecardFormatter interface {
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.
Comment on lines +25 to +27
Copy link
Member

Choose a reason for hiding this comment

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

👍

MarshalText() (string, error)
}
2 changes: 1 addition & 1 deletion pkg/k8sutil/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func GetGVKsFromAddToScheme(addToSchemeFunc func(*runtime.Scheme) error) ([]sche
}
schemeAllKnownTypes := s.AllKnownTypes()
ownGVKs := []schema.GroupVersionKind{}
for gvk, _ := range schemeAllKnownTypes {
for gvk := range schemeAllKnownTypes {
if !isKubeMetaKind(gvk.Kind) {
ownGVKs = append(ownGVKs, gvk)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/leader/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ func Become(ctx context.Context, lockName string) error {
log.Info("Found existing lock with my name. I was likely restarted.")
log.Info("Continuing as the leader.")
return nil
} else {
log.Info("Found existing lock", "LockOwner", existingOwner.Name)
}
log.Info("Found existing lock", "LockOwner", existingOwner.Name)
}
case apierrors.IsNotFound(err):
log.Info("No pre-existing lock was found.")
Expand Down
4 changes: 3 additions & 1 deletion pkg/test/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"k8s.io/client-go/restmapper"
)

type TestCtx struct {
type TestCtx struct { //nolint:golint
// todo(camilamacedo86): The no lint here is for type name will be used as test.TestCtx by other packages, and that stutters; consider calling this Ctx (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.
id string
cleanupFns []cleanupFn
namespace string
Expand Down