Skip to content

Commit

Permalink
Merge pull request #856 from iotaledger/chore/adapt-to-latest-linter
Browse files Browse the repository at this point in the history
Adapt .golangci.yml to latest version and fix linter issues
  • Loading branch information
alexsporn authored Mar 21, 2024
2 parents 50023f0 + c1af2a6 commit befbb3a
Show file tree
Hide file tree
Showing 89 changed files with 279 additions and 255 deletions.
75 changes: 51 additions & 24 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ linters-settings:
gocyclo:
min-complexity: 15
govet:
disable:
disable:
- shadow
misspell:
locale: US
Expand All @@ -29,94 +29,121 @@ linters-settings:
desc: Should be replaced with "github.com/iotaledger/hive.go/ierrors" package
- pkg: "github.com/pkg/errors"
desc: Should be replaced with "github.com/iotaledger/hive.go/ierrors" package
#custom:
# typegroupingcheck:
# path: ./typegroupingcheck/typegroupingcheck.so
# description: Check for grouped types in functions' parameters

linters:
# Disable all linters.
disable-all: true
# Enable specific linter
enable:
#- typegroupingcheck
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- asasalint
- asciicheck
- bidichk
- bodyclose
#- containedctx
#- contextcheck # this linter is buggy and renders all nolint rules useless
#- contextcheck # this linter is buggy and renders all nolint rules useless
- copyloopvar
#- cyclop
- decorder
- depguard
- dogsled
#- dupl
- dupword
- durationcheck
- errchkjson
- errname
#- errorlint
- errorlint
- execinquery
#- exhaustive
#- exhaustruct
- exportloopref
#- forbidigo
- forcetypeassert
#- funlen
#- gci
- ginkgolinter
- gocheckcompilerdirectives
#- gochecknoglobals
#- gochecknoinits
#- gochecksumtype
#- gocognit
- goconst
#- gocritic
- gocritic
#- gocyclo
- godot
#- godox
#- goerr113
- goerr113
- gofmt
#- gofumpt
- goheader
- goimports
#- gomnd
#- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosmopolitan
- grouper
- importas
#- interfacer
#- makezero
#- maligned
- inamedparam
#- interfacebloat
- intrange
#- ireturn
#- lll
- loggercheck
#- maintidx
- makezero
- mirror
- misspell
#- nakedret
- musttag
- nakedret
#- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
#- nonamedreturns
#- nosnakecase
#- nosprintfhostport
- nosprintfhostport
- paralleltest
#- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
#- scopelint
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- stylecheck
#- tagalign
- tagliatelle
- tenv
#- testpackage
#- thelper
- testableexamples
- testifylint
- testpackage
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
#- varnamelen
- wastedassign
- whitespace
#- wrapcheck
#- wsl
- zerologlint

issues:
exclude-dirs:
- components/dashboard
exclude-files:
- ".*_test.go$"
- "testframework.go"
- ".*.pb.go$"
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
Expand Down
12 changes: 7 additions & 5 deletions components/dashboard/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
Params: params,
Configure: configure,
Run: run,
IsEnabled: func(c *dig.Container) bool {
IsEnabled: func(*dig.Container) bool {
return ParamsDashboard.Enabled
},
}
Expand Down Expand Up @@ -117,11 +117,12 @@ func configureServer() {
server.Use(middleware.Recover())

if ParamsDashboard.BasicAuth.Enabled {
server.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
server.Use(middleware.BasicAuth(func(username, password string, _ echo.Context) (bool, error) {
if username == ParamsDashboard.BasicAuth.Username &&
password == ParamsDashboard.BasicAuth.Password {
return true, nil
}

return false, nil
}))
}
Expand Down Expand Up @@ -170,17 +171,17 @@ func currentNodeStatus() *nodestatus {
}

func neighborMetrics() []neighbormetric {
var stats []neighbormetric
if deps.NetworkManager == nil {
return stats
return []neighbormetric{}
}

// gossip plugin might be disabled
neighbors := deps.NetworkManager.AllNeighbors()
if neighbors == nil {
return stats
return []neighbormetric{}
}

stats := make([]neighbormetric, 0, len(neighbors))
for _, neighbor := range neighbors {
stats = append(stats, neighbormetric{
ID: neighbor.Peer().ID.String(),
Expand All @@ -189,5 +190,6 @@ func neighborMetrics() []neighbormetric {
PacketsWritten: neighbor.PacketsWritten(),
})
}

return stats
}
2 changes: 2 additions & 0 deletions components/dashboard/explorer_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func createExplorerBlock(block *model.Block, cachedBlock *blocks.Block, blockMet
if isBasic && basicBlock.Payload != nil && basicBlock.Payload.PayloadType() == iotago.PayloadSignedTransaction {
tx, _ := basicBlock.Payload.(*iotago.SignedTransaction)
txResponse := NewTransaction(tx)

//nolint:errchkjson
bytes, _ := json.Marshal(txResponse)

return bytes
Expand Down
14 changes: 11 additions & 3 deletions components/dashboard/jsonresponse.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:tagliatelle // we won't change the dashboard now
package dashboard

import (
Expand Down Expand Up @@ -211,8 +212,10 @@ func NewUnlockBlock(unlockBlock iotago.Unlock) *UnlockBlock {
Type: unlockBlock.Type().String(),
}

//nolint:gocritic
switch unlock := unlockBlock.(type) {
case *iotago.SignatureUnlock:
//nolint:gocritic
switch signature := unlock.Signature.(type) {
case *iotago.Ed25519Signature:
sigJSON, err := deps.Protocol.CommittedAPI().JSONEncode(signature)
Expand Down Expand Up @@ -244,11 +247,15 @@ type TransactionMetadata struct {
// NewTransactionMetadata returns the TransactionMetadata from the given mempool.TransactionMetadata.
func NewTransactionMetadata(transactionMetadata mempool.TransactionMetadata, conflicts ds.Set[iotago.TransactionID]) *TransactionMetadata {
var confirmationState string
if transactionMetadata.IsAccepted() {

switch {
case transactionMetadata.IsAccepted():
confirmationState = "accepted"
} else if transactionMetadata.IsPending() {

case transactionMetadata.IsPending():
confirmationState = "pending"
} else if transactionMetadata.IsRejected() {

case transactionMetadata.IsRejected():
confirmationState = "rejected"
}

Expand All @@ -259,6 +266,7 @@ func NewTransactionMetadata(transactionMetadata mempool.TransactionMetadata, con
for _, txID := range conflicts.ToSlice() {
strIDs = append(strIDs, txID.ToHex())
}

return strIDs
}(),
Booked: transactionMetadata.IsBooked(),
Expand Down
1 change: 0 additions & 1 deletion components/dashboard/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (
var ErrInvalidParameter = echo.NewHTTPError(http.StatusBadRequest, "invalid parameter")

func indexRoute(e echo.Context) error {

index, err := staticFS.Open(build + "/index.html")
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion components/dashboard/type.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:tagliatelle // we won't change the dashboard now
package dashboard

import (
Expand Down Expand Up @@ -125,7 +126,7 @@ type ExplorerBlock struct {
ID string `json:"id"`
// NetworkID is the network ID of the block that attaches to.
NetworkID iotago.NetworkID `json:"networkID"`
// ProtocolVersion is the protocol that proccess the block.
// ProtocolVersion is the protocol that process the block.
ProtocolVersion iotago.Version `json:"protocolVersion"`
// SolidificationTimestamp is the timestamp of the block.
SolidificationTimestamp int64 `json:"solidificationTimestamp"`
Expand Down
3 changes: 2 additions & 1 deletion components/dashboard/visualizer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:tagliatelle // we won't change the dashboard now
package dashboard

import (
Expand Down Expand Up @@ -60,6 +61,7 @@ func sendVertex(blk *blocks.Block, confirmed bool) {
return txMetadata.IsAccepted()
}
}

return false
}(),
}}, true)
Expand All @@ -82,7 +84,6 @@ func sendTipInfo(block *blocks.Block, isTip bool) {

func runVisualizer(component *app.Component) {
if err := component.Daemon().BackgroundWorker("Dashboard[Visualizer]", func(ctx context.Context) {

unhook := lo.Batch(
deps.Protocol.Events.Engine.Booker.TransactionAccepted.Hook(func(transactionMetadata mempool.TransactionMetadata) {
attachmentID := transactionMetadata.EarliestIncludedAttachment()
Expand Down
20 changes: 7 additions & 13 deletions components/dashboard/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import (
)

var (
// settings
// settings.
webSocketWriteTimeout = 3 * time.Second

// clients
// clients.
wsClientsMu syncutils.RWMutex
wsClients = make(map[uint64]*wsclient)
nextWsClientID uint64

// gorilla websocket layer
// gorilla websocket layer.
upgrader = websocket.Upgrader{
HandshakeTimeout: webSocketWriteTimeout,
CheckOrigin: func(r *http.Request) bool { return true },
CheckOrigin: func(*http.Request) bool { return true },
EnableCompression: true,
}
)
Expand Down Expand Up @@ -97,6 +97,7 @@ func registerWSClient() (uint64, *wsclient) {
}
wsClients[clientID] = wsClient
nextWsClientID++

return clientID, wsClient
}

Expand All @@ -120,6 +121,7 @@ func broadcastWsBlock(blk interface{}, dontDrop ...bool) {
case <-wsClient.exit:
case wsClient.channel <- blk:
}

return
}

Expand Down Expand Up @@ -166,15 +168,7 @@ func websocketRoute(c echo.Context) error {
break
}
}
return nil
}

func sendJSON(ws *websocket.Conn, blk *wsblk) error {
if err := ws.WriteJSON(blk); err != nil {
return err
}
if err := ws.SetWriteDeadline(time.Now().Add(webSocketWriteTimeout)); err != nil {
return err
}
//nolint:nilerr // false positive
return nil
}
15 changes: 5 additions & 10 deletions components/dashboard_metrics/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@ func configure() error {
})

routeGroup.GET(RouteDatabaseSizes, func(c echo.Context) error {
resp, err := databaseSizesMetrics()
if err != nil {
return err
}

return httpserver.JSONResponse(c, http.StatusOK, resp)
return httpserver.JSONResponse(c, http.StatusOK, databaseSizesMetrics())
})

return nil
Expand Down Expand Up @@ -102,19 +97,19 @@ func configureComponentCountersEvents() {
incComponentCounter(Received)
})

deps.Protocol.Events.Engine.PostSolidFilter.BlockAllowed.Hook(func(_ *blocks.Block) {
deps.Protocol.Events.Engine.PostSolidFilter.BlockAllowed.Hook(func(*blocks.Block) {
incComponentCounter(Allowed)
})

deps.Protocol.Events.Engine.BlockDAG.BlockSolid.Hook(func(b *blocks.Block) {
deps.Protocol.Events.Engine.BlockDAG.BlockSolid.Hook(func(*blocks.Block) {
incComponentCounter(Solidified)
})

deps.Protocol.Events.Engine.Booker.BlockBooked.Hook(func(b *blocks.Block) {
deps.Protocol.Events.Engine.Booker.BlockBooked.Hook(func(*blocks.Block) {
incComponentCounter(Booked)
})

deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(b *blocks.Block) {
deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(*blocks.Block) {
incComponentCounter(Scheduled)
})
}
Loading

0 comments on commit befbb3a

Please sign in to comment.