Skip to content

Commit

Permalink
fix lint errors (knative#388)
Browse files Browse the repository at this point in the history
* fix typo (misspell)

* ineffectual assignment to err (ineffassign)

* if block ends with a return statement, so drop this else and outdent its block (golint)

* should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (golint)

* struct field LogHttp should be LogHTTP (golint)

* fix last typo
  • Loading branch information
toshi0607 authored and knative-prow-robot committed Aug 25, 2019
1 parent 04a55b2 commit 699ac5e
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pkg/kn/commands/namespaced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestGetNamespaceDefault(t *testing.T) {
}

// test with all-namespaces flag set with sample namespace
// all-namespaces flag takes the precendence
// all-namespaces flag takes the precedence
func TestGetNamespaceAllNamespacesSet(t *testing.T) {
testCmd := testCommandGenerator(true)
expectedNamespace := ""
Expand All @@ -86,7 +86,7 @@ func TestGetNamespaceAllNamespacesSet(t *testing.T) {
}

// test with all-namespace flag set without any namespace flag set
// all-namespace flag takes precendence
// all-namespace flag takes precedence
func TestGetNamespaceDefaultAllNamespacesUnset(t *testing.T) {
testCmd := testCommandGenerator(true)
expectedNamespace := ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/plugin/plugin_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestPluginHandler(t *testing.T) {
})

t.Run("HandlePluginCommand", func(t *testing.T) {
t.Run("sucess handling", func(t *testing.T) {
t.Run("success handling", func(t *testing.T) {
setup(t)
defer cleanup(t)
beforeEach(t)
Expand Down
1 change: 1 addition & 0 deletions pkg/kn/commands/plugin/plugin_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func TestPluginList(t *testing.T) {
defer ctx.cleanup()

err := ctx.createTestPlugin(KnTestPluginName, FileModeExecutable, false)
assert.NilError(t, err)

err = ctx.execute("plugin", "list")
assert.NilError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/plugin/plugin_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/spf13/cobra"
)

// pluginVerifier verifies that existing kn commands are not overriden
// pluginVerifier verifies that existing kn commands are not overridden
type pluginVerifier struct {
root *cobra.Command
seenPlugins map[string]string
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/plugin/plugin_verifier_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/spf13/cobra"
)

// pluginVerifier verifies that existing kn commands are not overriden
// pluginVerifier verifies that existing kn commands are not overridden
type pluginVerifier struct {
root *cobra.Command
seenPlugins map[string]string
Expand Down
5 changes: 4 additions & 1 deletion pkg/kn/commands/service/service_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func TestServiceCreateEnv(t *testing.T) {
}

template, err := servinglib.RevisionTemplateOfService(created)
if err != nil {
t.Fatal(err)
}
actualEnvVars, err := servinglib.EnvToMap(template.Spec.Containers[0].Env)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -453,10 +456,10 @@ func TestServiceCreateEnvForce(t *testing.T) {
"B": "LIONS"}

template, err := servinglib.RevisionTemplateOfService(created)
actualEnvVars, err := servinglib.EnvToMap(template.Spec.Containers[0].Env)
if err != nil {
t.Fatal(err)
}
actualEnvVars, err := servinglib.EnvToMap(template.Spec.Containers[0].Env)
if err != nil {
t.Fatal(err)
} else if template.Spec.Containers[0].Image != "gcr.io/foo/bar:v2" {
Expand Down
3 changes: 3 additions & 0 deletions pkg/kn/commands/service/service_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
}

revisionDescs, err := getRevisionDescriptions(client, service, printDetails)
if err != nil {
return err
}

return describe(cmd.OutOrStdout(), service, revisionDescs)
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/service/service_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {

func preCheck(cmd *cobra.Command, args []string) error {
if cmd.Flags().NFlag() == 0 {
return errors.New(fmt.Sprintf("flag(s) not set\nUsage: %s", cmd.Use))
return fmt.Errorf("flag(s) not set\nUsage: %s", cmd.Use)
}

return nil
Expand Down
12 changes: 5 additions & 7 deletions pkg/kn/commands/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package commands

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -47,7 +46,7 @@ type KnParams struct {
NewClient func(namespace string) (serving_kn_v1alpha1.KnClient, error)

// General global options
LogHttp bool
LogHTTP bool

// Set this if you want to nail down the namespace
fixedCurrentNamespace string
Expand Down Expand Up @@ -82,7 +81,7 @@ func (params *KnParams) GetConfig() (serving_v1alpha1_client.ServingV1alpha1Inte
if err != nil {
return nil, err
}
if params.LogHttp {
if params.LogHTTP {
// TODO: When we update to the newer version of client-go, replace with
// config.Wrap() for future compat.
config.WrapTransport = util.NewLoggingTransport
Expand Down Expand Up @@ -110,9 +109,8 @@ func (params *KnParams) GetClientConfig() (clientcmd.ClientConfig, error) {

paths := filepath.SplitList(params.KubeCfgPath)
if len(paths) > 1 {
return nil, errors.New(fmt.Sprintf("Can not find config file. '%s' looks like a path. "+
"Please use the env var KUBECONFIG if you want to check for multiple configuration files", params.KubeCfgPath))
} else {
return nil, errors.New(fmt.Sprintf("Config file '%s' can not be found", params.KubeCfgPath))
return nil, fmt.Errorf("Can not find config file. '%s' looks like a path. "+
"Please use the env var KUBECONFIG if you want to check for multiple configuration files", params.KubeCfgPath)
}
return nil, fmt.Errorf("Config file '%s' can not be found", params.KubeCfgPath)
}
2 changes: 1 addition & 1 deletion pkg/kn/commands/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestGetConfig(t *testing.T) {
} {
p := &KnParams{
ClientConfig: tc.clientConfig,
LogHttp: tc.logHttp,
LogHTTP: tc.logHttp,
}

_, err := p.GetConfig()
Expand Down
8 changes: 3 additions & 5 deletions pkg/kn/core/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package core

import (
"errors"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -130,7 +129,7 @@ func NewKnCommand(params ...commands.KnParams) *cobra.Command {
// Persistent flags
rootCmd.PersistentFlags().StringVar(&commands.CfgFile, "config", "", "kn config file (default is $HOME/.kn/config.yaml)")
rootCmd.PersistentFlags().StringVar(&p.KubeCfgPath, "kubeconfig", "", "kubectl config file (default is $HOME/.kube/config)")
flags.AddBothBoolFlags(rootCmd.PersistentFlags(), &p.LogHttp, "log-http", "", false, "log http traffic")
flags.AddBothBoolFlags(rootCmd.PersistentFlags(), &p.LogHTTP, "log-http", "", false, "log http traffic")

plugin.AddPluginFlags(rootCmd)
plugin.BindPluginsFlagToViper(rootCmd)
Expand Down Expand Up @@ -175,10 +174,9 @@ func EmptyAndUnknownSubCommands(cmd *cobra.Command) {
fmt.Println()

if len(args) == 0 {
return errors.New(fmt.Sprintf("please provide a valid sub-command for \"kn %s\"", aCmd.Name()))
} else {
return errors.New(fmt.Sprintf("unknown sub-command \"%s\" for \"kn %s\"", args[0], aCmd.Name()))
return fmt.Errorf("please provide a valid sub-command for \"kn %s\"", aCmd.Name())
}
return fmt.Errorf("unknown sub-command \"%s\" for \"kn %s\"", args[0], aCmd.Name())
}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/kn/traffic/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ func verifyInputSanity(trafficFlags *flags.Traffic) error {
// To check if there are duplicate revision names in traffic flags
if _, exist := revisionRefMap[revisionRef]; exist {
return errorRepeatingRevision("--traffic", revisionRef)
} else {
revisionRefMap[revisionRef] = i
}
revisionRefMap[revisionRef] = i

percentInt, err := strconv.Atoi(percent)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/serving/schema_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package serving

import (
"errors"
"fmt"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -44,5 +43,5 @@ func GetGroupVersionKind(obj runtime.Object, gv schema.GroupVersion) (*schema.Gr
return &gvk, nil
}
}
return nil, errors.New(fmt.Sprintf("no group version %s registered in %s", gv, scheme.Scheme.Name()))
return nil, fmt.Errorf("no group version %s registered in %s", gv, scheme.Scheme.Name())
}
3 changes: 1 addition & 2 deletions pkg/util/parsing_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ func mapFromArray(arr []string, delimiter string, allowSingles bool) (map[string
if len(pairSlice) <= 1 {
if len(pairSlice) == 0 || !allowSingles {
return nil, fmt.Errorf("Argument requires a value that contains the %q character; got %q", delimiter, pairStr)
} else {
returnMap[pairSlice[0]] = ""
}
returnMap[pairSlice[0]] = ""
} else {
returnMap[pairSlice[0]] = pairSlice[1]
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewE2eTest(t *testing.T) *e2eTest {
}
}

// Setup set up an enviroment for kn integration test returns the Teardown cleanup function
// Setup set up an environment for kn integration test returns the Teardown cleanup function
func (test *e2eTest) Setup(t *testing.T) {
test.env.Namespace = fmt.Sprintf("%s%d", test.env.Namespace, getNamespaceCountAndIncrement())
test.kn = kn{t, test.env.Namespace, Logger{}}
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestService(t *testing.T) {

func (test *e2eTest) serviceCreateDuplicate(t *testing.T, serviceName string) {
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName}, runOpts{NoNamespace: false})
assert.NilError(t, err)
assert.Check(t, strings.Contains(out, serviceName), "The service does not exist yet")

_, err = test.kn.RunWithOpts([]string{"service", "create", serviceName,
Expand All @@ -65,6 +66,7 @@ func (test *e2eTest) serviceDescribeWithPrintFlags(t *testing.T, serviceName str

func (test *e2eTest) serviceDeleteNonexistent(t *testing.T, serviceName string) {
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName}, runOpts{NoNamespace: false})
assert.NilError(t, err)
assert.Check(t, !strings.Contains(out, serviceName), "The service exists")

_, err = test.kn.RunWithOpts([]string{"service", "delete", serviceName}, runOpts{NoNamespace: false, AllowError: true})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/traffic_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestTrafficSplit(t *testing.T) {
},
)
// test reducing number of targets from traffic blockdd
t.Run("remove a revision with tag old from traffic block entierly",
t.Run("remove a revision with tag old from traffic block entirely",
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
Expand Down

0 comments on commit 699ac5e

Please sign in to comment.