Skip to content

Commit

Permalink
chore: enable errcheck linter (#4162)
Browse files Browse the repository at this point in the history
* lint

* errcheck

* check errors in interface_flag.go

* set value in tests

* fix test

* always provide a value when testing flags

* add a comment to trigger ci

* changelog

* fix removed errors

---------

Co-authored-by: Danilo Pantani <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
3 people authored Jun 18, 2024
1 parent 2f69bf3 commit 52be059
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 32 deletions.
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 @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion ignite/internal/plugin/testdata/execute_fail/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ignite/internal/plugin/testdata/execute_ok/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
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: 1 addition & 3 deletions ignite/services/chain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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
1 change: 1 addition & 0 deletions integration/cosmosgen/bank_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion integration/plugin/testdata/example-plugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 52be059

Please sign in to comment.