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

fix: fix some lint issues #3691

Merged
merged 18 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
4 changes: 3 additions & 1 deletion .github/workflows/test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- '**.md'
branches:
- main
- release/*

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand All @@ -32,6 +33,7 @@ jobs:
if: env.GIT_DIFF
with:
version: v1.54.2
skip-cache: true
install-mode: goinstall
args: --timeout 10m
args: --timeout 20m
github-token: ${{ secrets.github_token }}
4 changes: 2 additions & 2 deletions ignite/cmd/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ ignite
rootCmd := buildRootCmd()
tt.setup(t, pi)

linkPlugins(rootCmd, []*plugin.Plugin{p})
_ = linkPlugins(rootCmd, []*plugin.Plugin{p})

if tt.expectedError != "" {
require.Error(p.Error)
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestLinkPluginHooks(t *testing.T) {
rootCmd := buildRootCmd()
tt.setup(t, pi)

linkPlugins(rootCmd, []*plugin.Plugin{p})
_ = linkPlugins(rootCmd, []*plugin.Plugin{p})

if tt.expectedError != "" {
require.EqualError(p.Error, tt.expectedError)
Expand Down
2 changes: 1 addition & 1 deletion ignite/internal/tools/gen-cli-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func generateCmd(cmd *cobra.Command, w io.Writer) error {
continue
}

io.WriteString(w, "\n")
_, _ = io.WriteString(w, "\n")

if err := generateCmd(cmd, w); err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions ignite/pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ func (c Cache[T]) Put(key string, value T) error {

// Get fetches the value of key within the namespace.
// If no value exists, it will return found == false.
func (c Cache[T]) Get(key string) (val T, err error) {
func (c Cache[T]) Get(key string) (T, error) {
var val T
db, err := openDB(c.storage.storagePath)
if err != nil {
return
return val, err
}
defer db.Close()

Expand Down
4 changes: 2 additions & 2 deletions ignite/pkg/cliui/clispinner/clispinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *Spinner) SetCharset(charset []string) *Spinner {

// SetColor sets the prefix for spinner.
func (s *Spinner) SetColor(color string) *Spinner {
s.sp.Color(color)
_ = s.sp.Color(color)
return s
}

Expand All @@ -107,7 +107,7 @@ func (s *Spinner) Start() *Spinner {
func (s *Spinner) Stop() *Spinner {
s.sp.Stop()
s.sp.Prefix = ""
s.sp.Color(spinnerColor)
_ = s.sp.Color(spinnerColor)
s.sp.UpdateCharSet(charset)
s.sp.Stop()
return s
Expand Down
4 changes: 2 additions & 2 deletions ignite/pkg/cliui/view/errorview/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func (e Error) String() string {

w := wordwrap.NewWriter(80)
w.Breakpoints = []rune{' '}
w.Write([]byte(s))
w.Close()
_, _ = w.Write([]byte(s))
_ = w.Close()

return colors.Error(w.String())
}
4 changes: 2 additions & 2 deletions ignite/pkg/cmdrunner/cmdrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ type cmdSignal struct {
*exec.Cmd
}

func (e *cmdSignal) Signal(s os.Signal) { e.Cmd.Process.Signal(s) }
func (e *cmdSignal) Signal(s os.Signal) { _ = e.Cmd.Process.Signal(s) }

func (e *cmdSignal) Write([]byte) (n int, err error) { return 0, nil }

Expand All @@ -199,7 +199,7 @@ type cmdSignalWithWriter struct {
w io.WriteCloser
}

func (e *cmdSignalWithWriter) Signal(s os.Signal) { e.Cmd.Process.Signal(s) }
func (e *cmdSignalWithWriter) Signal(s os.Signal) { _ = e.Cmd.Process.Signal(s) }

func (e *cmdSignalWithWriter) Write(data []byte) (n int, err error) {
defer e.w.Close()
Expand Down
13 changes: 7 additions & 6 deletions ignite/pkg/cosmosanalysis/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,31 +217,32 @@ func newUnexpectedTypeErr(n any) error {
return errors.Errorf("unexpected type %T", n)
}

func findBasicManagerRegistrations(n ast.Node, pkgDir string, fileImports map[string]string) (packages []string, err error) {
func findBasicManagerRegistrations(n ast.Node, pkgDir string, fileImports map[string]string) ([]string, error) {
callExprType, ok := n.(*ast.CallExpr)
if !ok {
return
return nil, nil
}

selectorExprType, ok := callExprType.Fun.(*ast.SelectorExpr)
if !ok {
return
return nil, nil
}

identExprType, ok := selectorExprType.X.(*ast.Ident)
if !ok {
return
return nil, nil
}
basicModulePkgName := findBasicManagerPkgName(fileImports)
if basicModulePkgName == "" {
// cosmos-sdk/types/module is not imported in this file, skip
return
return nil, nil
}
if identExprType.Name != basicModulePkgName || selectorExprType.Sel.Name != "NewBasicManager" {
return
return nil, nil
}

// Node "n" defines the call to NewBasicManager, let's loop on its args to discover modules
packages := make([]string, 0)
for _, arg := range callExprType.Args {
switch v := arg.(type) {

Expand Down
4 changes: 3 additions & 1 deletion ignite/pkg/cosmosanalysis/cosmosanalysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ func TestFindImplementationNotFound(t *testing.T) {

// No implementation
found, err := cosmosanalysis.FindImplementation(tmpDir1, expectedInterface)
require.NoError(t, err)
require.Len(t, found, 0)

// Partial implementation
found, err = cosmosanalysis.FindImplementation(tmpDir2, expectedInterface)
require.NoError(t, err)
require.Len(t, found, 0)
}

Expand Down Expand Up @@ -189,7 +191,7 @@ func TestFindAppFilePath(t *testing.T) {
appTestFilePath := filepath.Join(secondaryAppFolder, "my_own_app_test.go")
err = os.WriteFile(appTestFilePath, appTestFile, 0o644)
require.NoError(t, err)
pathFound, err = cosmosanalysis.FindAppFilePath(tmpDir)
_, err = cosmosanalysis.FindAppFilePath(tmpDir) //nolint:ineffassign
require.Error(t, err)
require.Contains(t, err.Error(), "cannot locate your app.go")

Expand Down
1 change: 1 addition & 0 deletions ignite/pkg/cosmosanalysis/testdata/chain/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c=
github.com/cometbft/cometbft v0.37.1/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs=
github.com/cometbft/cometbft v0.37.2/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs=
github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0=
github.com/confio/ics23/go v0.9.0/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e/mYVRak=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down
6 changes: 3 additions & 3 deletions ignite/pkg/cosmosfaucet/http_faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type FaucetInfoResponse struct {
}

func (f Faucet) faucetInfoHandler(w http.ResponseWriter, _ *http.Request) {
xhttp.ResponseJSON(w, http.StatusOK, FaucetInfoResponse{
_ = xhttp.ResponseJSON(w, http.StatusOK, FaucetInfoResponse{
IsAFaucet: true,
ChainID: f.chainID,
})
Expand All @@ -94,11 +94,11 @@ func (f Faucet) coinsFromRequest(req TransferRequest) (sdk.Coins, error) {
}

func responseSuccess(w http.ResponseWriter) {
xhttp.ResponseJSON(w, http.StatusOK, TransferResponse{})
_ = xhttp.ResponseJSON(w, http.StatusOK, TransferResponse{})
}

func responseError(w http.ResponseWriter, code int, err error) {
xhttp.ResponseJSON(w, code, TransferResponse{
_ = xhttp.ResponseJSON(w, code, TransferResponse{
Error: err.Error(),
})
}
2 changes: 1 addition & 1 deletion ignite/pkg/cosmosfaucet/http_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ type openAPIData struct {
}

func (f Faucet) openAPISpecHandler(w http.ResponseWriter, _ *http.Request) {
tmplOpenAPISpec.Execute(w, f.openAPIData)
_ = tmplOpenAPISpec.Execute(w, f.openAPIData)
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (a Adapter) Save(ctx context.Context, txs []cosmosclient.TX) error {
}

// Rollback won't have any effect if the transaction is committed before
defer sqlTx.Rollback()
defer sqlTx.Rollback() //nolint:errcheck

// Prepare insert statements to speed up "bulk" saving times
txStmt, err := sqlTx.PrepareContext(ctx, sqlInsertTX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ func TestQuery(t *testing.T) {
// Act
cr, err := adapter.Query(ctx, qry)
if cr.Next() {
cr.Scan(&rowValue)
err = cr.Scan(&rowValue)
require.NoError(t, err)
}

// Assert
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/debugger/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func Start(ctx context.Context, binaryPath string, options ...Option) (err error
return fmt.Errorf("failed to run debug server: %w", err)
}

defer server.Stop()
defer server.Stop() //nolint:errcheck

// Wait until the context is done or the connected client disconnects
select {
Expand Down
24 changes: 16 additions & 8 deletions ignite/pkg/jsonfile/jsonfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,28 @@ func (f *JSONFile) Field(key string, param interface{}) error {
switch dataType {
case jsonparser.Boolean, jsonparser.Array, jsonparser.Number, jsonparser.Object:
err := json.Unmarshal(value, param)
if _, ok := err.(*json.UnmarshalTypeError); ok { //nolint:errorlint
var unmarshalTypeError *json.UnmarshalTypeError
if errors.As(err, &unmarshalTypeError) {
return ErrInvalidValueType
} else if err != nil {
return err
}
case jsonparser.String:
paramStr, ok := param.(*string)
if !ok {
return ErrInvalidValueType
}
*paramStr, err = jsonparser.ParseString(value)
result, err := jsonparser.ParseString(value)
if err != nil {
return err
}
paramStr, ok := param.(*string)
if ok {
*paramStr = result
break
}
var (
unmarshalTypeError *json.UnmarshalTypeError
syntaxTypeError *json.SyntaxError
)
if err := json.Unmarshal(value, param); errors.As(err, &unmarshalTypeError) ||
errors.As(err, &syntaxTypeError) {
return ErrInvalidValueType
}
case jsonparser.NotExist:
case jsonparser.Null:
case jsonparser.Unknown:
Expand Down
39 changes: 26 additions & 13 deletions ignite/pkg/jsonfile/jsonfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ func TestJSONFile_Field(t *testing.T) {
}

func TestJSONFile_Update(t *testing.T) {
jsonCoins, err := json.Marshal(sdk.NewCoin("bar", sdk.NewInt(500)))
coins := sdk.NewCoin("bar", sdk.NewInt(500))
jsonCoins, err := json.Marshal(coins)
require.NoError(t, err)

tests := []struct {
name string
filepath string
opts []UpdateFileOption
want []interface{}
err error
}{
{
Expand All @@ -133,6 +135,7 @@ func TestJSONFile_Update(t *testing.T) {
"22020096",
),
},
want: []interface{}{float64(22020096)},
},
{
name: "update string field to number",
Expand All @@ -143,6 +146,7 @@ func TestJSONFile_Update(t *testing.T) {
22020096,
),
},
want: []interface{}{float64(22020096)},
},
{
name: "update number field",
Expand All @@ -153,19 +157,21 @@ func TestJSONFile_Update(t *testing.T) {
1000,
),
},
want: []interface{}{float64(1000)},
},
{
name: "update coin field",
name: "update timestamp field",
filepath: "testdata/jsonfile.json",
opts: []UpdateFileOption{
WithKeyValueTimestamp(
"genesis_time",
10000000,
),
},
want: nil, // TODO find a way to test timestamp values
},
{
name: "update all values type",
name: "update two values type",
filepath: "testdata/jsonfile.json",
opts: []UpdateFileOption{
WithKeyValue(
Expand All @@ -176,21 +182,22 @@ func TestJSONFile_Update(t *testing.T) {
"consensus_params.block.time_iota_ms",
1000,
),
WithKeyValueTimestamp(
"genesis_time",
999999999,
),
},
want: []interface{}{float64(3000000), float64(1000)},
},
{
name: "update bytes",
name: "update coin field",
filepath: "testdata/jsonfile.json",
opts: []UpdateFileOption{
WithKeyValueByte(
"app_state.crisis.params.constant_fee",
jsonCoins,
),
},
want: []interface{}{map[string]interface{}{
"denom": coins.Denom,
"amount": coins.Amount.String(),
}},
},
{
name: "add non-existing field",
Expand All @@ -201,6 +208,7 @@ func TestJSONFile_Update(t *testing.T) {
"111",
),
},
want: []interface{}{float64(111)},
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -238,10 +246,15 @@ func TestJSONFile_Update(t *testing.T) {
for _, opt := range tt.opts {
opt(updates)
}
for key, value := range updates {
newValue := value
err = f.Field(key, &newValue)
require.Equal(t, value, newValue)
if tt.want != nil {
got := make([]interface{}, 0)
for key := range updates {
var newValue interface{}
err := f.Field(key, &newValue)
require.NoError(t, err)
got = append(got, newValue)
}
require.ElementsMatch(t, tt.want, got)
}
})
}
Expand Down Expand Up @@ -333,7 +346,7 @@ func TestFromURL(t *testing.T) {
{
name: "invalid link",
args: args{
url: "https://github.com/invalid_example.json",
url: "https://google.com/invalid_example.json",
},
err: ErrInvalidURL,
},
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/openapiconsole/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Handler(title, specURL string) http.HandlerFunc {
t, _ := template.ParseFS(index, "index.tpl")

return func(w http.ResponseWriter, req *http.Request) {
t.Execute(w, struct {
_ = t.Execute(w, struct {
Title string
URL string
}{
Expand Down
Loading
Loading