Skip to content

Commit

Permalink
Update golangci-lint to 1.52.2 (#56)
Browse files Browse the repository at this point in the history
Some of the updated linters require go 1.19 so this commit updates the
github workflow to use go 1.19 for the "check" section.

Note that "allow-leading-space" is no longer supported as mentioned in
golangci/golangci-lint#3063 (comment)

Fix new warnings that are now reported.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
  • Loading branch information
marckhouzam authored and vuil committed May 2, 2023
1 parent 0662d8d commit 437cc6d
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19
id: go

- name: go cache
Expand Down
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ linters-settings:
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
Expand Down
4 changes: 2 additions & 2 deletions component/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ func NewObjectWriter(output io.Writer, outputFormat string, data interface{}) Ou
}

// SetKeys sets the values to use as the keys for the output values.
func (obw *objectwriter) SetKeys(headerKeys ...string) {
func (obw *objectwriter) SetKeys(_ ...string) {
// Object writer does not have the concept of keys
fmt.Fprintln(obw.out, "Programming error, attempt to add headers to object output")
}

// AddRow appends a new row to our table.
func (obw *objectwriter) AddRow(items ...interface{}) {
func (obw *objectwriter) AddRow(_ ...interface{}) {
// Object writer does not have the concept of keys
fmt.Fprintln(obw.out, "Programming error, attempt to add rows to object output")
}
Expand Down
2 changes: 1 addition & 1 deletion config/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func SetContext(c *configtypes.Context, setCurrent bool) error {
}

// Set current server
if setCurrent && s.Type == configtypes.ManagementClusterServerType { // nolint:staticcheck
if setCurrent && s.Type == configtypes.ManagementClusterServerType { //nolint:staticcheck
persist, err = setCurrentServer(node, s.Name)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions config/discovery_sources_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func setDiscoverySource(discoverySourcesNode *yaml.Node, discoverySource configt
}

func getDiscoverySourceTypeAndName(discoverySource configtypes.PluginDiscovery) (string, string) {
if discoverySource.GCP != nil && discoverySource.GCP.Name != "" { // nolint:staticcheck
return DiscoveryTypeGCP, discoverySource.GCP.Name // nolint:staticcheck
if discoverySource.GCP != nil && discoverySource.GCP.Name != "" { //nolint:staticcheck
return DiscoveryTypeGCP, discoverySource.GCP.Name //nolint:staticcheck
} else if discoverySource.OCI != nil && discoverySource.OCI.Name != "" {
return DiscoveryTypeOCI, discoverySource.OCI.Name
} else if discoverySource.Local != nil && discoverySource.Local.Name != "" {
Expand Down
5 changes: 1 addition & 4 deletions config/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ func copyFile(src, dst string) error {
if err != nil {
return err
}
if err := os.Chmod(dst, sf.Mode()); err != nil {
return err
}
return nil
return os.Chmod(dst, sf.Mode())
}

// copyDir copies a directory tree recursively. Source directory must exist and destination directory must *not*
Expand Down
2 changes: 1 addition & 1 deletion hack/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BIN_DIR := bin

GOIMPORTS_VERSION=0.1.12
VALE_VERSION=2.20.1
GOLANGCI_LINT_VERSION=1.46.0
GOLANGCI_LINT_VERSION=1.52.2
MISSPELL_VERSION=0.3.4
GINKGO_VERSION=2.9.0

Expand Down
6 changes: 3 additions & 3 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (l *logger) Print(msg string, err error, logType string, kvs ...interface{}
if err != nil {
values = append(values, "error", err)
}
header := []byte(l.header(logType, l.callDepth))
header := []byte(l.header(l.callDepth))
_, _ = logWriter.Write(header, []byte(l.getLogString(values)), l.Enabled(), l.level, logType)
}

Expand Down Expand Up @@ -228,7 +228,7 @@ func copySlice(in []interface{}) []interface{} {
// - Variables name are not quoted, eg.
// This is a message "Var1"="value" --> This is a message Var1="value"
// - Variables are not sorted, thus allowing full control to the developer on the output.
func flatten(entry logEntry) (string, error) { // nolint:gocyclo
func flatten(entry logEntry) (string, error) { //nolint:gocyclo
var msgValue string
var errorValue error
if len(entry.Values)%2 == 1 {
Expand Down Expand Up @@ -297,7 +297,7 @@ func pretty(value interface{}) (string, error) {
return string(jb), nil
}

func (l *logger) header(logType string, depth int) string {
func (l *logger) header(depth int) string {
_, file, line, ok := runtime.Caller(3 + depth)
if !ok {
file = "???"
Expand Down
6 changes: 4 additions & 2 deletions test/compatibility/framework/context_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
// Return: command to execute or error if any validations fails for SetContextInputOptions or SetContextOutputOptions
// This method does validate the input parameters SetContextInputOptions or SetContextOutputOptions based on Runtime API Version
// For more details about supported parameters refer to SetContextInputOptions or SetContextOutputOptions definition(and ContextOpts struct, which is embedded)
// nolint:dupl
//
//nolint:dupl
func NewSetContextCommand(inputOpts *SetContextInputOptions, outputOpts *SetContextOutputOptions) (*core.Command, error) {
// Init the Command object
c := &core.Command{}
Expand Down Expand Up @@ -146,7 +147,8 @@ func NewGetContextCommand(inputOpts *GetContextInputOptions, outputOpts *GetCont
// Return: command to execute or error if any validations fails for DeleteContextInputOptions or DeleteContextOutputOptions
// This method does validate the input parameters DeleteContextInputOptions or DeleteContextOutputOptions based on Runtime API Version
// For more details about supported parameters refer to DeleteContextInputOptions or DeleteContextOutputOptions definition(and ContextOpts struct, which is embedded)
// nolint: dupl
//
//nolint:dupl
func NewDeleteContextCommand(inputOpts *DeleteContextInputOptions, outputOpts *DeleteContextOutputOptions) (*core.Command, error) {
// Init the Command object
c := &core.Command{}
Expand Down
6 changes: 4 additions & 2 deletions test/compatibility/framework/server_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
// Return: command to execute or error if any validations fails for SetServerInputOptions or SetServerOutputOptions
// This method does validate the input parameters SetServerInputOptions or SetServerOutputOptions based on Runtime API Version
// For more details about supported parameters refer to SetServerInputOptions or SetServerOutputOptions definition(and ServerOpts struct, which is embedded)
// nolint:dupl
//
//nolint:dupl
func NewSetServerCommand(inputOpts *SetServerInputOptions, outputOpts *SetServerOutputOptions) (*core.Command, error) {
// Init the Command object
c := &core.Command{}
Expand Down Expand Up @@ -146,7 +147,8 @@ func NewGetServerCommand(inputOpts *GetServerInputOptions, outputOpts *GetServer
// Return: command to execute or error if any validations fails for DeleteServerInputOptions or DeleteServerOutputOptions
// This method does validate the input parameters DeleteServerInputOptions or DeleteServerOutputOptions based on Runtime API Version
// For more details about supported parameters refer to DeleteServerInputOptions or DeleteServerOutputOptions definition(and ServerOpts struct, which is embedded)
// nolint: dupl
//
//nolint:dupl
func NewDeleteServerCommand(inputOpts *DeleteServerInputOptions, outputOpts *DeleteServerOutputOptions) (*core.Command, error) {
// Init the Command object
c := &core.Command{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func parseContext(context string) (*configtypes.Context, error) {
}

// parseServer unmarshalls string to Server struct
func parseServer(server string) (*configtypes.Server, error) { // nolint:staticcheck // Deprecated
var s configtypes.Server // nolint:staticcheck // Deprecated
func parseServer(server string) (*configtypes.Server, error) { //nolint:staticcheck // Deprecated
var s configtypes.Server //nolint:staticcheck // Deprecated
err := yaml.Unmarshal([]byte(server), &s)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func triggerRemoveCurrentServerAPI(api *core.API) *core.APIResponse {

func getServer(serverName string) *core.APIResponse {
// Call runtime GetServer API
server, err := configlib.GetServer(serverName) // nolint:staticcheck // Deprecated
server, err := configlib.GetServer(serverName) //nolint:staticcheck // Deprecated
if err != nil {
return &core.APIResponse{
ResponseType: core.ErrorResponse,
Expand All @@ -105,9 +105,9 @@ func getServer(serverName string) *core.APIResponse {
}
}

func setServer(server *configtypes.Server, setCurrent bool) *core.APIResponse { // nolint:staticcheck // Deprecated
func setServer(server *configtypes.Server, setCurrent bool) *core.APIResponse { //nolint:staticcheck // Deprecated
// Call runtime SetServer API
err := configlib.AddServer(server, setCurrent) // nolint:staticcheck // Deprecated
err := configlib.AddServer(server, setCurrent) //nolint:staticcheck // Deprecated
if err != nil {
return &core.APIResponse{
ResponseType: core.ErrorResponse,
Expand All @@ -122,7 +122,7 @@ func setServer(server *configtypes.Server, setCurrent bool) *core.APIResponse {

func removeServer(serverName string) *core.APIResponse {
// Call runtime RemoveServer API
err := configlib.RemoveServer(serverName) // nolint:staticcheck // Deprecated
err := configlib.RemoveServer(serverName) //nolint:staticcheck // Deprecated

if err != nil {
return &core.APIResponse{
Expand All @@ -138,7 +138,7 @@ func removeServer(serverName string) *core.APIResponse {

func setCurrentServer(serverName string) *core.APIResponse {
// Call runtime SetCurrentServer API
err := configlib.SetCurrentServer(serverName) // nolint:staticcheck // Deprecated
err := configlib.SetCurrentServer(serverName) //nolint:staticcheck // Deprecated
if err != nil {
return &core.APIResponse{
ResponseType: core.ErrorResponse,
Expand All @@ -152,7 +152,7 @@ func setCurrentServer(serverName string) *core.APIResponse {
}

func getCurrentServer() *core.APIResponse {
server, err := configlib.GetCurrentServer() // nolint:staticcheck // Deprecated
server, err := configlib.GetCurrentServer() //nolint:staticcheck // Deprecated
if err != nil {
return &core.APIResponse{
ResponseType: core.ErrorResponse,
Expand All @@ -172,7 +172,7 @@ func getCurrentServer() *core.APIResponse {
}

func removeCurrentServer(serverName string) *core.APIResponse {
err := configlib.RemoveCurrentServer(serverName) // nolint:staticcheck // Deprecated
err := configlib.RemoveCurrentServer(serverName) //nolint:staticcheck // Deprecated
if err != nil {
return &core.APIResponse{
ResponseType: core.ErrorResponse,
Expand Down
4 changes: 2 additions & 2 deletions test/exec/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func WithEnv(args ...string) Option {

// Run executes the command and returns stdout, stderr and the error if there is any.
func (c *Command) Run(ctx context.Context) ([]byte, []byte, error) {
cmd := exec.CommandContext(ctx, c.Cmd, c.Args...) // nolint:gosec
cmd := exec.CommandContext(ctx, c.Cmd, c.Args...) //nolint:gosec
if len(c.Env) != 0 {
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, c.Env...)
Expand Down Expand Up @@ -109,7 +109,7 @@ func (c *Command) Run(ctx context.Context) ([]byte, []byte, error) {

// RunAndRedirectOutput executes command and redirects output
func (c *Command) RunAndRedirectOutput(ctx context.Context) error {
cmd := exec.CommandContext(ctx, c.Cmd, c.Args...) // nolint:gosec
cmd := exec.CommandContext(ctx, c.Cmd, c.Args...) //nolint:gosec

if len(c.Env) != 0 {
cmd.Env = os.Environ()
Expand Down
2 changes: 1 addition & 1 deletion test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func copyAndCapture(w io.Writer, r io.Reader) ([]byte, error) {
var out []byte
buf := make([]byte, 1024)
for {
// nolint:gocritic
//nolint:gocritic
n, err := r.Read(buf[:])
if n > 0 {
d := buf[:n]
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/helloworld/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var PrintCmd = &cobra.Command{
RunE: printHelloWorld,
}

func printHelloWorld(cmd *cobra.Command, args []string) error {
func printHelloWorld(_ *cobra.Command, _ []string) error {
fmt.Printf("Hello world from test plugin")
return nil
}

0 comments on commit 437cc6d

Please sign in to comment.