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 all 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 @@ -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 @@
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)

Check warning on line 19 in ignite/cmd/completion.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/completion.go#L17-L19

Added lines #L17 - L19 were not covered by tests
}
os.Exit(0)
}
var err error

Check warning on line 23 in ignite/cmd/completion.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/completion.go#L23

Added line #L23 was not covered by tests
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
err = cmd.Root().GenBashCompletion(os.Stdout)

Check warning on line 26 in ignite/cmd/completion.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/completion.go#L26

Added line #L26 was not covered by tests
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
err = cmd.Root().GenZshCompletion(os.Stdout)

Check warning on line 28 in ignite/cmd/completion.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/completion.go#L28

Added line #L28 was not covered by tests
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
err = cmd.Root().GenFishCompletion(os.Stdout, true)

Check warning on line 30 in ignite/cmd/completion.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/completion.go#L30

Added line #L30 was not covered by tests
case "powershell":
cmd.Root().GenPowerShellCompletion(os.Stdout)
err = cmd.Root().GenPowerShellCompletion(os.Stdout)

Check warning on line 32 in ignite/cmd/completion.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/completion.go#L32

Added line #L32 was not covered by tests
default:
cmd.Help()
err = cmd.Help()

Check warning on line 34 in ignite/cmd/completion.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/completion.go#L34

Added line #L34 was not covered by tests
}
if err != nil {
fmt.Fprintln(os.Stderr, "Error generating completion script:", err)
os.Exit(1)

Check warning on line 38 in ignite/cmd/completion.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/completion.go#L36-L38

Added lines #L36 - L38 were not covered by tests
}
},
}
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 @@
}
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

Check warning on line 76 in ignite/internal/tools/gen-cli-docs/main.go

View check run for this annotation

Codecov / codecov/patch

ignite/internal/tools/gen-cli-docs/main.go#L75-L76

Added lines #L75 - L76 were not covered by tests
}

// 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 @@

if _, err := os.Stat(gentxDir); os.IsNotExist(err) {
return false, nil
}
if err != nil {
// Return error on other error
} else if err != nil {

Check warning on line 231 in ignite/services/chain/init.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/chain/init.go#L231

Added line #L231 was not covered by tests
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 @@
}

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

Check warning on line 46 in ignite/services/plugin/grpc/v1/interface_flag.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/plugin/grpc/v1/interface_flag.go#L46

Added line #L46 was not covered by tests
}
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

Check warning on line 56 in ignite/services/plugin/grpc/v1/interface_flag.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/plugin/grpc/v1/interface_flag.go#L56

Added line #L56 was not covered by tests
}
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

Check warning on line 66 in ignite/services/plugin/grpc/v1/interface_flag.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/plugin/grpc/v1/interface_flag.go#L66

Added line #L66 was not covered by tests
}
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

Check warning on line 76 in ignite/services/plugin/grpc/v1/interface_flag.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/plugin/grpc/v1/interface_flag.go#L76

Added line #L76 was not covered by tests
}
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

Check warning on line 86 in ignite/services/plugin/grpc/v1/interface_flag.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/plugin/grpc/v1/interface_flag.go#L86

Added line #L86 was not covered by tests
}
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

Check warning on line 92 in ignite/services/plugin/grpc/v1/interface_flag.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/plugin/grpc/v1/interface_flag.go#L92

Added line #L92 was not covered by tests
}
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

Check warning on line 97 in ignite/services/plugin/grpc/v1/interface_flag.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/plugin/grpc/v1/interface_flag.go#L97

Added line #L97 was not covered by tests
}
}
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
Loading