Skip to content

Commit

Permalink
build: golangci-lint v1.53.2 (decred#1966)
Browse files Browse the repository at this point in the history
  • Loading branch information
dajohi committed Jun 14, 2023
1 parent 5346713 commit 7bdba75
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 159 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Build and Test
on: [push, pull_request]
permissions:
contents: read

jobs:
build-go:
name: Go Build and Test
Expand All @@ -10,25 +11,21 @@ jobs:
matrix:
go: ['1.19', '1.20']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #v3.5.2

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 #v4.0.1
with:
go-version: ${{ matrix.go }}

- name: Go Build dcrdata
env:
GO111MODULE: "on"
run: go build -v ./...
working-directory: ./cmd/dcrdata

- name: Install Linters
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.1"
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.2"

- name: Go Tests
env:
GO111MODULE: "on"
run: |
./run_tests.sh
Expand All @@ -39,10 +36,10 @@ jobs:
matrix:
node-version: [16.x, 18.x]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #v3.5.2

- name: Use nodejs ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c #v3.6.0
with:
node-version: ${{ matrix.node-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #v3.5.2
- name: Build the Docker image
run: docker build -t decred/dcrdata:$(date +%s) .
27 changes: 27 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
run:
deadline: 10m

output:
format: github-actions,colored-line-number

linters:
disable-all: true
enable:
- asciicheck
- bidichk
- durationcheck
- exportloopref
- gofmt
- goimports
- gosimple
- govet
- grouper
- ineffassign
- makezero
- misspell
- nosprintfhostport
- reassign
- tparallel
- typecheck
- unconvert
- unparam
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17 as daemon
FROM golang:1.20 as daemon

COPY . /go/src
WORKDIR /go/src/cmd/dcrdata
Expand All @@ -11,7 +11,7 @@ COPY ./cmd/dcrdata /root
RUN npm install
RUN npm run build

FROM golang:1.17
FROM golang:1.20
WORKDIR /
COPY --from=daemon /go/src/cmd/dcrdata/dcrdata /dcrdata
COPY --from=daemon /go/src/cmd/dcrdata/views /views
Expand Down
6 changes: 0 additions & 6 deletions api/types/apicache.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,6 @@ func (pq *BlockPriorityQueue) UpdateBlock(b *CachedBlock, summary *BlockDataBasi
}
}

func (pq *BlockPriorityQueue) lastAccessTime() time.Time {
pq.mtx.RLock()
defer pq.mtx.RUnlock()
return pq.lastAccess
}

func (pq *BlockPriorityQueue) setAccessTime(t time.Time) {
pq.mtx.Lock()
defer pq.mtx.Unlock()
Expand Down
2 changes: 0 additions & 2 deletions cmd/swapscan/swapscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ var start = flag.Uint64("start", 491_705, "Start block height")
var end = flag.Uint64("end", 1<<32, "End block height")

var (
activeNetParams = chaincfg.MainNetParams()

backendLog *slog.Backend
rpcclientLogger slog.Logger
)
Expand Down
19 changes: 0 additions & 19 deletions db/cache/addresscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,6 @@ func addressRows(rows []*dbtypes.AddressRowCompact, N, offset int) []*dbtypes.Ad
return []*dbtypes.AddressRowCompact{}
}

func addressRowsMerged(rows []*dbtypes.AddressRowMerged, N, offset int) []*dbtypes.AddressRowMerged {
if rows == nil {
return nil
}
numRows := len(rows)
if offset >= numRows {
return []*dbtypes.AddressRowMerged{}
}

end := offset + N
if end > numRows {
end = numRows
}
if offset < end {
return rows[offset:end]
}
return []*dbtypes.AddressRowMerged{}
}

// CreditAddressRows returns up to N credit (funding) address rows from the
// given AddressRow slice, starting after skipping offset rows. The input rows
// may only be of type []dbtypes.AddressRowCompact or
Expand Down
2 changes: 2 additions & 0 deletions db/cache/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,8 @@ func (charts *ChartData) Update() error {
for _, updater := range charts.updaters {
ti := time.Now()
stateID := charts.StateID()
// The Appender checks rows.Err
// nolint:rowserrcheck
rows, cancel, err := updater.Fetcher(charts)
if err != nil {
err = fmt.Errorf("error encountered during charts %s update. aborting update: %v", updater.Tag, err)
Expand Down
6 changes: 0 additions & 6 deletions db/cache/charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cache

import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
Expand All @@ -18,11 +17,6 @@ import (

var tempDir string

func printJson(thing interface{}) {
s, _ := json.MarshalIndent(thing, "", " ")
fmt.Println(string(s))
}

// TestMain setups the tempDir and cleans it up after tests.
func TestMain(m *testing.M) {
var err error
Expand Down
50 changes: 0 additions & 50 deletions db/dcrpg/pgblockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3138,56 +3138,6 @@ func (pgb *ChainDB) PowerlessTickets() (*apitypes.PowerlessTickets, error) {
return retrievePowerlessTickets(ctx, pgb.db)
}

// ticketsByBlocks fetches the tickets by blocks output count chart data from
// retrieveTicketByOutputCount
// This chart has been deprecated. Leaving ticketsByBlocks for possible future
// re-appropriation, says buck54321 on April 24, 2019.
func (pgb *ChainDB) ticketsByBlocks(heightArr, soloArr, pooledArr []uint64) ([]uint64,
[]uint64, []uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()

var err error
heightArr, soloArr, pooledArr, err = retrieveTicketByOutputCount(ctx,
pgb.db, 1, outputCountByAllBlocks, heightArr, soloArr, pooledArr)
if err != nil {
err = fmt.Errorf("ticketsByBlocks: %w", pgb.replaceCancelError(err))
}

return heightArr, soloArr, pooledArr, err
}

// ticketsByTPWindows fetches the tickets by ticket pool windows count chart data
// from retrieveTicketByOutputCount.
// This chart has been deprecated. Leaving ticketsByTPWindows for possible
// future re-appropriation, says buck54321 on April 24, 2019.
func (pgb *ChainDB) ticketsByTPWindows(heightArr, soloArr, pooledArr []uint64) ([]uint64,
[]uint64, []uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()

var err error
heightArr, soloArr, pooledArr, err = retrieveTicketByOutputCount(ctx, pgb.db,
pgb.chainParams.StakeDiffWindowSize, outputCountByTicketPoolWindow,
heightArr, soloArr, pooledArr)
if err != nil {
err = fmt.Errorf("ticketsByTPWindows: %w", pgb.replaceCancelError(err))
}

return heightArr, soloArr, pooledArr, err
}

// getChartData returns the chart data if it exists and initializes a new chart
// data instance if otherwise.
func (pgb *ChainDB) getChartData(data map[string]*dbtypes.ChartsData,
chartT string) *dbtypes.ChartsData {
cData := data[chartT]
if cData == nil {
cData = new(dbtypes.ChartsData)
}
return cData
}

// SetVinsMainchainByBlock first retrieves for all transactions in the specified
// block the vin_db_ids and vout_db_ids arrays, along with mainchain status,
// from the transactions table, and then sets the is_mainchain flag in the vins
Expand Down
27 changes: 0 additions & 27 deletions db/dcrpg/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1305,33 +1305,6 @@ func SetSpendingForTickets(db *sql.DB, ticketDbIDs, spendDbIDs []uint64,
return totalTicketsUpdated, dbtx.Commit()
}

// setSpendingForTickets is identical to SetSpendingForTickets except it takes a
// database transaction that was begun and will be committed by the caller.
func setSpendingForTickets(dbtx *sql.Tx, ticketDbIDs, spendDbIDs []uint64,
blockHeights []int64, spendTypes []dbtypes.TicketSpendType,
poolStatuses []dbtypes.TicketPoolStatus) error {
stmt, err := dbtx.Prepare(internal.SetTicketSpendingInfoForTicketDbID)
if err != nil {
return fmt.Errorf("tickets SELECT prepare failed: %w", err)
}

rowsAffected := make([]int64, len(ticketDbIDs))
for i, ticketDbID := range ticketDbIDs {
rowsAffected[i], err = sqlExecStmt(stmt, "failed to set ticket spending info: ",
ticketDbID, blockHeights[i], spendDbIDs[i], spendTypes[i], poolStatuses[i])
if err != nil {
_ = stmt.Close()
return err
}
if rowsAffected[i] != 1 {
log.Warnf("Updated spending info for %d tickets, expecting just 1!",
rowsAffected[i])
}
}

return stmt.Close()
}

// --- addresses table ---

// InsertAddressRow inserts an AddressRow (input or output), returning the row
Expand Down
8 changes: 0 additions & 8 deletions db/dcrpg/rewind.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,10 @@ func deleteVoutsForBlockSubQry(dbTx SqlExecutor, hash string) (rowsDeleted int64
return sqlExec(dbTx, internal.DeleteVoutsSubQry, "failed to delete vouts", hash)
}

func deleteVinsForBlock(dbTx SqlExecutor, hash string) (rowsDeleted int64, err error) {
return sqlExec(dbTx, internal.DeleteVins, "failed to delete vins", hash)
}

func deleteVinsForBlockSubQry(dbTx SqlExecutor, hash string) (rowsDeleted int64, err error) {
return sqlExec(dbTx, internal.DeleteVinsSubQry, "failed to delete vins", hash)
}

func deleteAddressesForBlock(dbTx SqlExecutor, hash string) (rowsDeleted int64, err error) {
return sqlExec(dbTx, internal.DeleteAddresses, "failed to delete addresses", hash)
}

func deleteAddressesForBlockSubQry(dbTx SqlExecutor, hash string) (rowsDeleted int64, err error) {
return sqlExec(dbTx, internal.DeleteAddressesSubQry, "failed to delete addresses", hash)
}
Expand Down
15 changes: 0 additions & 15 deletions pubsub/psclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,6 @@ func (c *Client) send(msg []byte) error {
return err
}

func (c *Client) newRequestID() int64 {
c.reqMtx.Lock()
reqID := c.nextRequestID
c.nextRequestID++
c.reqMtx.Unlock()
return reqID
}

func (c *Client) responseChan(reqID int64) chan *pstypes.ResponseMessage {
c.reqMtx.Lock()
defer c.reqMtx.Unlock()
Expand Down Expand Up @@ -462,13 +454,6 @@ func (c *Client) receiveMsg() (*pstypes.WebSocketMessage, error) {
return c.receiveMsgTimeout(c.readTimeout)
}

// receiveRaw for a message, returned undecoded as a string.
func (c *Client) receiveRaw() (message string, err error) {
_ = c.SetReadDeadline(time.Now().Add(c.readTimeout))
err = websocket.Message.Receive(c.Conn, &message)
return
}

// DecodeMsg attempts to decode the Message content of the given
// WebSocketMessage based on its EventId. The type contained in the returned
// interface{} depends on the EventId.
Expand Down
15 changes: 1 addition & 14 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,7 @@ for MODPATH in $MODPATHS; do
echo "==> ${module}"
(cd "${module}"
go test $TESTTAGS ./...
golangci-lint run --deadline=10m \
--out-format=github-actions,colored-line-number \
--disable-all \
--enable govet \
--enable staticcheck \
--enable gosimple \
--enable unconvert \
--enable ineffassign \
--enable structcheck \
--enable goimports \
--enable misspell \
--enable unparam \
--enable asciicheck \
--enable makezero
golangci-lint run
if [[ "$GV" =~ ^1.20 ]]; then
MOD_STATUS=$(git status --porcelain go.mod go.sum)
go mod tidy
Expand Down

0 comments on commit 7bdba75

Please sign in to comment.