Skip to content
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

chore: enable errcheck linter #4162

Merged
merged 18 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
8 changes: 1 addition & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ linters:
- depguard
- dogsled
- dupword
# - errcheck
- errcheck
- errchkjson
- errorlint
- exhaustive
Expand All @@ -19,12 +19,10 @@ linters:
- godot
- gofumpt
- revive
# - gosec
- gosimple
- govet
- grouper
- ineffassign
# - interfacer
- misspell
- nakedret
- nolintlint
Expand All @@ -40,8 +38,6 @@ linters:
- unparam
- misspell
- forbidigo
# - wrapcheck
# - wsl

linters-settings:
gci:
Expand Down Expand Up @@ -70,7 +66,5 @@ linters-settings:
issues:
exclude-dirs:
- ignite/ui
# # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
max-issues-per-linter: 0
max-same-issues: 0
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

### Changes


- [#4162](https://github.com/ignite/cli/pull/4162) Enable errcheck linter and fix a bug in the way we test flags
- [#4159](https://github.com/ignite/cli/pull/4159) Enable gci linter
- [#4157](https://github.com/ignite/cli/pull/4157) Upgrade golang to 1.22
- [#4094](https://github.com/ignite/cli/pull/4094) Scaffolding a multi-index map using `ignite s map foo bar baz --index foobar,foobaz` is no longer supported. Use one index instead of use `collections.IndexedMap`.
Expand Down
21 changes: 15 additions & 6 deletions ignite/cmd/completion.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ignitecmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
Expand All @@ -13,20 +14,28 @@ func NewCompletionCmd() *cobra.Command {
Short: "Generates shell completion script.",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
if err := cmd.Help(); err != nil {
fmt.Fprintln(os.Stderr, "Error displaying help:", err)
os.Exit(1)
}
os.Exit(0)
}
var err error
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
err = cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
err = cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
err = cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
cmd.Root().GenPowerShellCompletion(os.Stdout)
err = cmd.Root().GenPowerShellCompletion(os.Stdout)
default:
cmd.Help()
err = cmd.Help()
}
if err != nil {
fmt.Fprintln(os.Stderr, "Error generating completion script:", err)
os.Exit(1)
}
},
}
Expand Down
4 changes: 2 additions & 2 deletions ignite/cmd/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func TestLinkPluginCmds(t *testing.T) {
Use: "flaggy",
Flags: []*plugin.Flag{
{Name: "flag1", Type: plugin.FlagTypeString},
{Name: "flag2", Type: plugin.FlagTypeInt, DefaultValue: "0"},
{Name: "flag2", Type: plugin.FlagTypeInt, DefaultValue: "0", Value: "0"},
},
}
)

// helper to assert pluginInterface.Execute() calls
expectExecute := func(t *testing.T, ctx context.Context, p *mocks.PluginInterface, cmd *plugin.Command) {
expectExecute := func(t *testing.T, _ context.Context, p *mocks.PluginInterface, cmd *plugin.Command) {
t.Helper()
p.EXPECT().
Execute(
Expand Down
7 changes: 3 additions & 4 deletions ignite/internal/plugin/testdata/execute_fail/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module execute_fail

go 1.21.1
go 1.22

toolchain go1.21.5
toolchain go1.22.3

require (
github.com/hashicorp/go-plugin v1.6.0
Expand Down Expand Up @@ -82,7 +82,6 @@ require (
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.etcd.io/bbolt v1.3.9 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
Expand All @@ -95,5 +94,5 @@ require (
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
7 changes: 3 additions & 4 deletions ignite/internal/plugin/testdata/execute_ok/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module execute_ok

go 1.21.1
go 1.22

toolchain go1.21.5
toolchain go1.22.3

require (
github.com/hashicorp/go-plugin v1.6.0
Expand Down Expand Up @@ -82,7 +82,6 @@ require (
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.etcd.io/bbolt v1.3.9 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
Expand All @@ -95,5 +94,5 @@ require (
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 3 additions & 1 deletion ignite/internal/tools/gen-cli-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ func run() error {
}
defer cleanUp()
cmd.Flags().String(outFlag, ".", ".md file path to place Ignite CLI docs inside")
cmd.Flags().MarkHidden(outFlag)
if err := cmd.Flags().MarkHidden(outFlag); err != nil {
return err
}

// Run ExecuteC so cobra adds the completion command.
cmd, err = cmd.ExecuteC()
Expand Down
7 changes: 6 additions & 1 deletion ignite/pkg/cosmosgen/cosmosgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cosmosgen

import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -137,7 +138,11 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir
return err
}

defer b.Cleanup()
defer func() {
if err := b.Cleanup(); err != nil {
fmt.Println("Cleanup error:", err)
}
}()

g := &generator{
buf: b,
Expand Down
3 changes: 1 addition & 2 deletions ignite/pkg/gomodule/gomodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,10 @@ func FindModule(ctx context.Context, rootDir, path string) (Module, error) {

for dec.More() {
var m Module
if dec.Decode(&m); err != nil {
if err := dec.Decode(&m); err != nil {
if errors.Is(err, io.EOF) {
break
}

return Module{}, err
}

Expand Down
4 changes: 0 additions & 4 deletions ignite/services/chain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ func (c *Chain) IsInitialized() (bool, error) {
if _, err := os.Stat(gentxDir); os.IsNotExist(err) {
return false, nil
}
if err != nil {
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
// Return error on other error
return false, err
}

return true, nil
}
Expand Down
28 changes: 21 additions & 7 deletions ignite/services/plugin/grpc/v1/interface_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,46 +42,60 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error {
}

fs.BoolP(f.Name, f.Shorthand, v, f.Usage)
fs.Set(f.Name, f.Value)
if err := fs.Set(f.Name, f.Value); err != nil {
return err
}
case Flag_TYPE_FLAG_INT:
v, err := strconv.Atoi(f.DefaultValue)
if err != nil {
return newDefaultFlagValueError(cobraFlagTypeInt, f.DefaultValue)
}

fs.IntP(f.Name, f.Shorthand, v, f.Usage)
fs.Set(f.Name, f.Value)
if err := fs.Set(f.Name, f.Value); err != nil {
return err
}
case Flag_TYPE_FLAG_UINT:
v, err := strconv.ParseUint(f.DefaultValue, 10, 64)
if err != nil {
return newDefaultFlagValueError(cobraFlagTypeUint, f.DefaultValue)
}

fs.UintP(f.Name, f.Shorthand, uint(v), f.Usage)
fs.Set(f.Name, f.Value)
if err := fs.Set(f.Name, f.Value); err != nil {
return err
}
case Flag_TYPE_FLAG_INT64:
v, err := strconv.ParseInt(f.DefaultValue, 10, 64)
if err != nil {
return newDefaultFlagValueError(cobraFlagTypeInt64, f.DefaultValue)
}

fs.Int64P(f.Name, f.Shorthand, v, f.Usage)
fs.Set(f.Name, f.Value)
if err := fs.Set(f.Name, f.Value); err != nil {
return err
}
case Flag_TYPE_FLAG_UINT64:
v, err := strconv.ParseUint(f.DefaultValue, 10, 64)
if err != nil {
return newDefaultFlagValueError(cobraFlagTypeInt64, f.DefaultValue)
}

fs.Uint64P(f.Name, f.Shorthand, v, f.Usage)
fs.Set(f.Name, f.Value)
if err := fs.Set(f.Name, f.Value); err != nil {
return err
}
case Flag_TYPE_FLAG_STRING_SLICE:
s := strings.Trim(f.DefaultValue, "[]")
fs.StringSliceP(f.Name, f.Shorthand, strings.Fields(s), f.Usage)
fs.Set(f.Name, strings.Trim(f.Value, "[]"))
if err := fs.Set(f.Name, strings.Trim(f.Value, "[]")); err != nil {
return err
}
case Flag_TYPE_FLAG_STRING_UNSPECIFIED:
fs.StringP(f.Name, f.Shorthand, f.DefaultValue, f.Usage)
fs.Set(f.Name, f.Value)
if err := fs.Set(f.Name, f.Value); err != nil {
return err
}
}
return nil
}
Expand Down
14 changes: 14 additions & 0 deletions ignite/services/plugin/grpc/v1/types_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,48 +149,55 @@ func TestExecutedCommandNewFlags(t *testing.T) {
Shorthand: "b",
Usage: "bool usage",
DefaultValue: "false",
Value: "true",
Type: v1.Flag_TYPE_FLAG_BOOL,
},
{
Name: "int",
Shorthand: "i",
Usage: "int usage",
DefaultValue: "0",
Value: "42",
Type: v1.Flag_TYPE_FLAG_INT,
},
{
Name: "uint",
Shorthand: "u",
Usage: "uint usage",
DefaultValue: "0",
Value: "42",
Type: v1.Flag_TYPE_FLAG_UINT,
},
{
Name: "int64",
Shorthand: "j",
Usage: "int64 usage",
DefaultValue: "0",
Value: "42",
Type: v1.Flag_TYPE_FLAG_INT64,
},
{
Name: "uint64",
Shorthand: "k",
Usage: "uint64 usage",
DefaultValue: "0",
Value: "42",
Type: v1.Flag_TYPE_FLAG_UINT64,
},
{
Name: "string",
Shorthand: "s",
Usage: "string usage",
DefaultValue: "",
Value: "hello",
Type: v1.Flag_TYPE_FLAG_STRING_UNSPECIFIED,
},
{
Name: "string-slice",
Shorthand: "l",
Usage: "string slice usage",
DefaultValue: "[]",
Value: "[]",
Type: v1.Flag_TYPE_FLAG_STRING_SLICE,
},
{
Expand Down Expand Up @@ -247,6 +254,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) {
Shorthand: "b",
Usage: "bool usage",
DefaultValue: "false",
Value: "true",
Type: v1.Flag_TYPE_FLAG_BOOL,
Persistent: true,
},
Expand All @@ -255,6 +263,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) {
Shorthand: "i",
Usage: "int usage",
DefaultValue: "0",
Value: "42",
Type: v1.Flag_TYPE_FLAG_INT,
Persistent: true,
},
Expand All @@ -263,6 +272,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) {
Shorthand: "u",
Usage: "uint usage",
DefaultValue: "0",
Value: "42",
Type: v1.Flag_TYPE_FLAG_UINT,
Persistent: true,
},
Expand All @@ -271,6 +281,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) {
Shorthand: "j",
Usage: "int64 usage",
DefaultValue: "0",
Value: "42",
Type: v1.Flag_TYPE_FLAG_INT64,
Persistent: true,
},
Expand All @@ -279,6 +290,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) {
Shorthand: "k",
Usage: "uint64 usage",
DefaultValue: "0",
Value: "42",
Type: v1.Flag_TYPE_FLAG_UINT64,
Persistent: true,
},
Expand All @@ -287,6 +299,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) {
Shorthand: "s",
Usage: "string usage",
DefaultValue: "",
Value: "hello",
Type: v1.Flag_TYPE_FLAG_STRING_UNSPECIFIED,
Persistent: true,
},
Expand All @@ -295,6 +308,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) {
Shorthand: "l",
Usage: "string slice usage",
DefaultValue: "[]",
Value: "[]",
Type: v1.Flag_TYPE_FLAG_STRING_SLICE,
Persistent: true,
},
Expand Down
Loading
Loading