diff --git a/.golangci.yml b/.golangci.yml index fd302aa6ec..767184522f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,7 +9,7 @@ linters: - depguard - dogsled - dupword - # - errcheck + - errcheck - errchkjson - errorlint - exhaustive @@ -19,12 +19,10 @@ linters: - godot - gofumpt - revive - # - gosec - gosimple - govet - grouper - ineffassign - # - interfacer - misspell - nakedret - nolintlint @@ -40,8 +38,6 @@ linters: - unparam - misspell - forbidigo - # - wrapcheck - # - wsl linters-settings: gci: @@ -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 diff --git a/changelog.md b/changelog.md index a1755b5c5a..8f1390a8c2 100644 --- a/changelog.md +++ b/changelog.md @@ -25,6 +25,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`. diff --git a/go.mod b/go.mod index 4b91d19df2..9a0008354c 100644 --- a/go.mod +++ b/go.mod @@ -47,6 +47,7 @@ require ( github.com/goccy/go-yaml v1.11.3 github.com/golangci/golangci-lint v1.57.2 github.com/google/go-github/v48 v48.2.0 + github.com/google/go-querystring v1.1.0 github.com/gorilla/mux v1.8.1 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.6.0 @@ -270,7 +271,6 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-containerregistry v0.19.1 // indirect github.com/google/go-dap v0.11.0 // indirect - github.com/google/go-querystring v1.1.0 // indirect github.com/google/pprof v0.0.0-20240509144519-723abb6459b7 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gordonklaus/ineffassign v0.1.0 // indirect diff --git a/ignite/cmd/completion.go b/ignite/cmd/completion.go index 385a36ff1d..8edb10c51d 100644 --- a/ignite/cmd/completion.go +++ b/ignite/cmd/completion.go @@ -1,6 +1,7 @@ package ignitecmd import ( + "fmt" "os" "github.com/spf13/cobra" @@ -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) } }, } diff --git a/ignite/cmd/plugin_test.go b/ignite/cmd/plugin_test.go index 7513e016d5..d4cf70fede 100644 --- a/ignite/cmd/plugin_test.go +++ b/ignite/cmd/plugin_test.go @@ -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( diff --git a/ignite/internal/plugin/testdata/execute_fail/go.mod b/ignite/internal/plugin/testdata/execute_fail/go.mod index 692db54a4b..93c6b097b1 100644 --- a/ignite/internal/plugin/testdata/execute_fail/go.mod +++ b/ignite/internal/plugin/testdata/execute_fail/go.mod @@ -24,7 +24,7 @@ require ( github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-sdk v0.50.6 // indirect + github.com/cosmos/cosmos-sdk v0.50.7 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.16.0 // indirect diff --git a/ignite/internal/plugin/testdata/execute_ok/go.mod b/ignite/internal/plugin/testdata/execute_ok/go.mod index 30c13651f0..f012ea498e 100644 --- a/ignite/internal/plugin/testdata/execute_ok/go.mod +++ b/ignite/internal/plugin/testdata/execute_ok/go.mod @@ -24,7 +24,7 @@ require ( github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-sdk v0.50.6 // indirect + github.com/cosmos/cosmos-sdk v0.50.7 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.16.0 // indirect diff --git a/ignite/internal/tools/gen-cli-docs/main.go b/ignite/internal/tools/gen-cli-docs/main.go index 0883b1736b..03382fe466 100644 --- a/ignite/internal/tools/gen-cli-docs/main.go +++ b/ignite/internal/tools/gen-cli-docs/main.go @@ -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() diff --git a/ignite/pkg/gomodule/gomodule.go b/ignite/pkg/gomodule/gomodule.go index 6a4aec5273..cdbadb2ba9 100644 --- a/ignite/pkg/gomodule/gomodule.go +++ b/ignite/pkg/gomodule/gomodule.go @@ -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 } diff --git a/ignite/services/chain/init.go b/ignite/services/chain/init.go index aaa710b5d6..129933f27a 100644 --- a/ignite/services/chain/init.go +++ b/ignite/services/chain/init.go @@ -228,9 +228,7 @@ func (c *Chain) IsInitialized() (bool, error) { if _, err := os.Stat(gentxDir); os.IsNotExist(err) { return false, nil - } - if err != nil { - // Return error on other error + } else if err != nil { return false, err } diff --git a/ignite/services/plugin/grpc/v1/interface_flag.go b/ignite/services/plugin/grpc/v1/interface_flag.go index 8369d476c2..c3836f0ce4 100644 --- a/ignite/services/plugin/grpc/v1/interface_flag.go +++ b/ignite/services/plugin/grpc/v1/interface_flag.go @@ -42,7 +42,9 @@ 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 { @@ -50,7 +52,9 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error { } 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 { @@ -58,7 +62,9 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error { } 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 { @@ -66,7 +72,9 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error { } 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 { @@ -74,14 +82,20 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error { } 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 } diff --git a/ignite/services/plugin/grpc/v1/types_command_test.go b/ignite/services/plugin/grpc/v1/types_command_test.go index 0547684a35..8958006ac7 100644 --- a/ignite/services/plugin/grpc/v1/types_command_test.go +++ b/ignite/services/plugin/grpc/v1/types_command_test.go @@ -149,6 +149,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "b", Usage: "bool usage", DefaultValue: "false", + Value: "true", Type: v1.Flag_TYPE_FLAG_BOOL, }, { @@ -156,6 +157,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "i", Usage: "int usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_INT, }, { @@ -163,6 +165,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "u", Usage: "uint usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_UINT, }, { @@ -170,6 +173,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "j", Usage: "int64 usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_INT64, }, { @@ -177,6 +181,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "k", Usage: "uint64 usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_UINT64, }, { @@ -184,6 +189,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "s", Usage: "string usage", DefaultValue: "", + Value: "hello", Type: v1.Flag_TYPE_FLAG_STRING_UNSPECIFIED, }, { @@ -191,6 +197,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "l", Usage: "string slice usage", DefaultValue: "[]", + Value: "[]", Type: v1.Flag_TYPE_FLAG_STRING_SLICE, }, { @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index 435e27a5eb..774f1c8822 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -14,6 +14,7 @@ import ( envtest "github.com/ignite/cli/v29/integration" ) +// TestBankModule tests the bank module by creating accounts, transferring tokens between them, and querying the account balances. func TestBankModule(t *testing.T) { t.Skip() diff --git a/integration/plugin/testdata/example-plugin/go.mod b/integration/plugin/testdata/example-plugin/go.mod index 3033d77639..1cbc0ada56 100644 --- a/integration/plugin/testdata/example-plugin/go.mod +++ b/integration/plugin/testdata/example-plugin/go.mod @@ -22,7 +22,7 @@ require ( github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-sdk v0.50.6 // indirect + github.com/cosmos/cosmos-sdk v0.50.7 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.16.0 // indirect