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 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
1 change: 1 addition & 0 deletions .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 Down
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
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 @@

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

Check warning on line 96 in ignite/pkg/cliui/clispinner/clispinner.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cliui/clispinner/clispinner.go#L96

Added line #L96 was not covered by tests
return s
}

Expand All @@ -107,7 +107,7 @@
func (s *Spinner) Stop() *Spinner {
s.sp.Stop()
s.sp.Prefix = ""
s.sp.Color(spinnerColor)
_ = s.sp.Color(spinnerColor)

Check warning on line 110 in ignite/pkg/cliui/clispinner/clispinner.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cliui/clispinner/clispinner.go#L110

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

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

Check warning on line 25 in ignite/pkg/cliui/view/errorview/error.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cliui/view/errorview/error.go#L24-L25

Added lines #L24 - L25 were not covered by tests

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 @@
*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) }

Check warning on line 192 in ignite/pkg/cmdrunner/cmdrunner.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cmdrunner/cmdrunner.go#L192

Added line #L192 was not covered by tests

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

Expand All @@ -199,7 +199,7 @@
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
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)
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 @@
}

func (f Faucet) faucetInfoHandler(w http.ResponseWriter, _ *http.Request) {
xhttp.ResponseJSON(w, http.StatusOK, FaucetInfoResponse{
_ = xhttp.ResponseJSON(w, http.StatusOK, FaucetInfoResponse{

Check warning on line 72 in ignite/pkg/cosmosfaucet/http_faucet.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosfaucet/http_faucet.go#L72

Added line #L72 was not covered by tests
IsAFaucet: true,
ChainID: f.chainID,
})
Expand All @@ -94,11 +94,11 @@
}

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

Check warning on line 97 in ignite/pkg/cosmosfaucet/http_faucet.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosfaucet/http_faucet.go#L97

Added line #L97 was not covered by tests
}

func responseError(w http.ResponseWriter, code int, err error) {
xhttp.ResponseJSON(w, code, TransferResponse{
_ = xhttp.ResponseJSON(w, code, TransferResponse{

Check warning on line 101 in ignite/pkg/cosmosfaucet/http_faucet.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosfaucet/http_faucet.go#L101

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

func (f Faucet) openAPISpecHandler(w http.ResponseWriter, _ *http.Request) {
tmplOpenAPISpec.Execute(w, f.openAPIData)
_ = tmplOpenAPISpec.Execute(w, f.openAPIData)

Check warning on line 24 in ignite/pkg/cosmosfaucet/http_openapi.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosfaucet/http_openapi.go#L24

Added line #L24 was not covered by tests
}
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 @@
return fmt.Errorf("failed to run debug server: %w", err)
}

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

Check warning on line 127 in ignite/pkg/debugger/server.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/debugger/server.go#L127

Added line #L127 was not covered by tests

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

Check warning on line 204 in ignite/pkg/jsonfile/jsonfile.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/jsonfile/jsonfile.go#L203-L204

Added lines #L203 - L204 were not covered by tests
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 @@
t, _ := template.ParseFS(index, "index.tpl")

return func(w http.ResponseWriter, req *http.Request) {
t.Execute(w, struct {
_ = t.Execute(w, struct {

Check warning on line 17 in ignite/pkg/openapiconsole/console.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/openapiconsole/console.go#L17

Added line #L17 was not covered by tests
Title string
URL string
}{
Expand Down
9 changes: 6 additions & 3 deletions ignite/pkg/truncatedbuffer/truncatedbuffer_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package truncatedbuffer

import (
"math/rand"
"crypto/rand"
"testing"

"github.com/stretchr/testify/require"
)

func TestWriter(t *testing.T) {
ranBytes10 := make([]byte, 10)
rand.Read(ranBytes10)
_, err := rand.Read(ranBytes10)
require.NoError(t, err)

ranBytes1000 := make([]byte, 1000)
rand.Read(ranBytes1000)
_, err = rand.Read(ranBytes1000)
require.NoError(t, err)

// TruncatedBuffer has a max capacity
b := NewTruncatedBuffer(100)
Expand Down
9 changes: 7 additions & 2 deletions ignite/pkg/xgenny/xgenny.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@

for _, entry := range entries {
if entry.IsDir() {
w.walkDir(wl, filepath.Join(path, entry.Name()))
err := w.walkDir(wl, filepath.Join(path, entry.Name()))
if err != nil {
return err
}

Check warning on line 45 in ignite/pkg/xgenny/xgenny.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/xgenny/xgenny.go#L44-L45

Added lines #L44 - L45 were not covered by tests
continue
}

Expand All @@ -57,7 +60,9 @@
return err
}

wl(trimPath, f)
if err := wl(trimPath, f); err != nil {
return err
}

Check warning on line 65 in ignite/pkg/xgenny/xgenny.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/xgenny/xgenny.go#L64-L65

Added lines #L64 - L65 were not covered by tests
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/xhttp/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ResponseJSON(w http.ResponseWriter, status int, data interface{}) error {
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
w.Write(bz)
_, _ = w.Write(bz)
return err
}

Expand Down
Loading