Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemmsilva committed Apr 23, 2024
1 parent 3311201 commit a5adb28
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ linters:
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- exportloopref # Checks for pointers to enclosing loop variables.
- funlen # Tool for detection of long functions.
- goconst # Finds repeated strings that could be replaced by a constant.
- gocritic # Provides many diagnostics that check for bugs, performance and style issues.
- gocyclo # Computes and checks the cyclomatic complexity of functions.
- goerr113 # Golang linter to check the errors handling expressions.
Expand Down Expand Up @@ -186,6 +185,7 @@ linters:
- wastedassign # wastedassign finds wasted assignment statements. [fast: true, auto-fix: false]


# - goconst # Finds repeated strings that could be replaced by a constant.
# - depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
# nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false]
# don't enable:
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/solidity/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func StorageEncodeString(slotNumber uint8, s string) (ret map[common.Hash]common
ret[mainSlot] = common.BigToHash(big.NewInt(int64(len(s)*2) + 1))

i := 0
for len(s) > 0 {
for s != "" {
var chunk common.Hash
copy(chunk[:], s)

Expand Down
4 changes: 3 additions & 1 deletion packages/nodeconn/nodeconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func (nc *nodeConnection) RefreshOnLedgerRequests(ctx context.Context, chainID i
if !ok {
panic("unexpected chainID")
}
ncChain.refreshOwnedOutputs(ctx)
if err := ncChain.refreshOwnedOutputs(ctx); err != nil {
nc.LogError(fmt.Sprintf("error refreshing outputs: %s", err.Error()))
}
}

func New(
Expand Down
2 changes: 1 addition & 1 deletion packages/trie/test/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestProofScenariosBlake2b(t *testing.T) {
p := trr.MerkleProof([]byte(k))
err = p.Validate(root.Bytes())
require.NoError(t, err)
if len(v) > 0 {
if v != "" {
cID := trie.CommitToData([]byte(v))
err = p.ValidateWithTerminal(root.Bytes(), cID.Bytes())
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions packages/trie/test/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func runUpdateScenario(trieUpdatable *trie.TrieUpdatable, store trie.KVStore, sc
continue // key must not be empty
}
key = []byte(before)
if len(after) > 0 {
if after != "" {
value = []byte(after)
}
} else {
Expand Down Expand Up @@ -333,11 +333,11 @@ func checkResult(t *testing.T, trie *trie.TrieUpdatable, checklist map[string]st
for key, expectedValue := range checklist {
v := trie.GetStr(key)
if traceScenarios {
if len(v) > 0 {
if v != "" {
fmt.Printf("FOUND '%s': '%s' (expected '%s')\n", key, v, expectedValue)
} else {
fmt.Printf("NOT FOUND '%s' (expected '%s')\n", key, func() string {
if len(expectedValue) > 0 {
if expectedValue != "" {
return "FOUND"
}
return "NOT FOUND"
Expand Down
2 changes: 1 addition & 1 deletion packages/trie/trie_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (tr *TrieUpdatable) delete(triePath []byte) {
nodes[i-1].removeChild(nil, idxAsChild)
}
}
assertf(nodes[0] != nil, "please do not delete root") //nolint:gosec // false positive
assertf(nodes[0] != nil, "please do not delete root")

Check failure on line 205 in packages/trie/trie_kvstore.go

View workflow job for this annotation

GitHub Actions / Lint

G602: Potentially accessing slice out of bounds (gosec)
}

func (tr *TrieUpdatable) mergeNodeIfNeeded(node *bufferedNode) *bufferedNode {
Expand Down
27 changes: 12 additions & 15 deletions packages/util/pipe/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,11 @@ func TestLimitPriorityLimitedPriorityHashQueueTwice(t *testing.T) {
return 3*index/2 - 20
}
return (3*index - 41) / 2
} else {
if index%2 == 1 {
return (3*index - 139) / 2
}
return 3*index/2 - 70
}
if index%2 == 1 {
return (3*index - 139) / 2
}
return 3*index/2 - 70
}
testQueueTwice(NewSimpleNothashableFactory(), q, elementsToAddSingle, alwaysTrueFun, limit, resultFun, t)
}
Expand Down Expand Up @@ -262,12 +261,11 @@ func testPriorityQueueTwice[E IntConvertible](factory Factory[E], makePriorityQu
return 3*index/2 - 50
}
return (3*index - 101) / 2
} else {
if index%2 == 1 {
return (3*index - 199) / 2
}
return 3*index/2 - 100
}
if index%2 == 1 {
return (3*index - 199) / 2
}
return 3*index/2 - 100
}
testQueueTwice(factory, q, elementsToAddSingle, alwaysTrueFun, 2*elementsToAddSingle, resultFun, t)
}
Expand Down Expand Up @@ -354,12 +352,11 @@ func TestLimitPriorityHashLimitedPriorityHashQueueDuplicates(t *testing.T) {
return 3*index - 40
}
return 3*index - 41
} else {
if index%2 == 0 {
return 3*index - 139
}
return 3*index - 140
}
if index%2 == 0 {
return 3*index - 139
}
return 3*index - 140
}
testQueueBasicAddLengthPeekRemove(NewSimpleHashableFactory(), q, 3*elementsToAddFirstIteration, addFun, addResultFun, limit, resultFun, t)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/core/governance/governanceimpl/chaininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func getChainInfo(ctx isc.SandboxView) dict.Dict {
ret.Set(governance.VarGasFeePolicyBytes, info.GasFeePolicy.Bytes())
ret.Set(governance.VarGasLimitsBytes, info.GasLimits.Bytes())

if len(info.PublicURL) > 0 {
if info.PublicURL != "" {
ret.Set(governance.VarPublicURL, codec.EncodeString(info.PublicURL))
}

Expand Down
2 changes: 1 addition & 1 deletion packages/webapi/controllers/chain/waitforrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *Controller) waitForRequestToFinish(e echo.Context) error {
timeout := defaultTimeoutSeconds * time.Second

timeoutInSeconds := e.QueryParam("timeoutSeconds")
if len(timeoutInSeconds) > 0 {
if timeoutInSeconds != "" {
parsedTimeout, _ := strconv.Atoi(timeoutInSeconds)

if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions tools/schema/model/yaml/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func (n *Node) toStringElt() model.DefElt {

func (n *Node) toDefElt() *model.DefElt {
comment := ""
if len(n.HeadComment) > 0 {
if n.HeadComment != "" {
// remove trailing '\n' and space
comment = strings.TrimSpace(n.HeadComment)
} else if len(n.LineComment) > 0 {
} else if n.LineComment != "" {
// remove trailing '\n' and space
comment = strings.TrimSpace(n.LineComment)
}
Expand Down Expand Up @@ -126,9 +126,9 @@ func (n *Node) toDefMapMap() model.DefMapMap {
continue
}
comment := ""
if len(yamlKey.HeadComment) > 0 {
if yamlKey.HeadComment != "" {
comment = strings.TrimSpace(yamlKey.HeadComment) // remove trailing '\n'
} else if len(yamlKey.LineComment) > 0 {
} else if yamlKey.LineComment != "" {
comment = strings.TrimSpace(yamlKey.LineComment) // remove trailing '\n'
}

Expand All @@ -146,9 +146,9 @@ func (n *Node) toDefMapMap() model.DefMapMap {
func (n *Node) toFuncDef() model.FuncDef {
def := model.FuncDef{}
def.Line = n.Line
if len(n.HeadComment) > 0 {
if n.HeadComment != "" {
def.Comment = strings.TrimSpace(n.HeadComment) // remove trailing '\n'
} else if len(n.LineComment) > 0 {
} else if n.LineComment != "" {
def.Comment = strings.TrimSpace(n.LineComment) // remove trailing '\n'
}

Expand All @@ -164,9 +164,9 @@ func (n *Node) toFuncDef() model.FuncDef {
return model.FuncDef{}
}
def.Access = *yamlKey.Contents[0].toDefElt()
if len(yamlKey.HeadComment) > 0 {
if yamlKey.HeadComment != "" {
def.Access.Comment = strings.TrimSpace(yamlKey.HeadComment) // remove trailing '\n'
} else if len(yamlKey.LineComment) > 0 {
} else if yamlKey.LineComment != "" {
def.Access.Comment = strings.TrimSpace(yamlKey.LineComment) // remove trailing '\n'
}
case KeyParams:
Expand All @@ -188,9 +188,9 @@ func (n *Node) toFuncDefMap() model.FuncDefMap {
continue
}
comment := ""
if len(yamlKey.HeadComment) > 0 {
if yamlKey.HeadComment != "" {
comment = strings.TrimSpace(yamlKey.HeadComment) // remove trailing '\n'
} else if len(yamlKey.LineComment) > 0 {
} else if yamlKey.LineComment != "" {
comment = strings.TrimSpace(yamlKey.LineComment) // remove trailing '\n'
}
key := model.DefElt{
Expand Down

0 comments on commit a5adb28

Please sign in to comment.