Skip to content

Commit

Permalink
fix: fix some lint issues (#3691)
Browse files Browse the repository at this point in the history
* update lint and add some lint fixes

* remove panic from faucet responses

* improve jsonfile tests

* fix some lint issues

* remove unused file

* fix more lint issue

* fix error handler for plugins tests

* rollback some test assertions

* rollback lint ci file

* remove unused files and comments

---------

Co-authored-by: Pantani <Pantani>
  • Loading branch information
Pantani committed Oct 19, 2023
1 parent 7436d93 commit d91979b
Show file tree
Hide file tree
Showing 27 changed files with 105 additions and 61 deletions.
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 @@ 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
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 @@ 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)
}
2 changes: 1 addition & 1 deletion ignite/pkg/cosmostxcollector/adapter/postgres/postgres.go
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
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 @@ func (w Walker) walkDir(wl packd.WalkFunc, path string) error {

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
}
continue
}

Expand All @@ -57,7 +60,9 @@ func (w Walker) walkDir(wl packd.WalkFunc, path string) error {
return err
}

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

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

0 comments on commit d91979b

Please sign in to comment.