Skip to content

Commit

Permalink
chore: lint: update golangci lint config
Browse files Browse the repository at this point in the history
* remove and replace some linters
* remove some exclusions
* make all exclusions more explicit matches
  • Loading branch information
rvagg authored and ribasushi committed May 16, 2024
1 parent 46200e1 commit b3ac64c
Show file tree
Hide file tree
Showing 64 changed files with 137 additions and 172 deletions.
69 changes: 28 additions & 41 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ linters:
- govet
- goimports
- misspell
- goconst
- golint
- revive
- errcheck
- gosec
- unconvert
- staticcheck
- varcheck
- deadcode
- scopelint
- exportloopref
- unused

# We don't want to skip builtin/
Expand All @@ -25,37 +22,36 @@ skip-dirs:

issues:
exclude:
- "by other packages, and that stutters; consider calling this"
- "Potential file inclusion via variable"
- "should have( a package)? comment"
- "Error return value of `logging.SetLogLevel` is not checked"
- "comment on exported"
- "(func|method) \\w+ should be \\w+"
- "(type|var|struct field|(method|func) parameter) `\\w+` should be `\\w+`"
- "(G306|G301|G307|G108|G302|G204|G104)"
- "don't use ALL_CAPS in Go names"
- "string .* has .* occurrences, make it a constant"
- "a blank import should be only in a main or test package, or have a comment justifying it"
- "package comment should be of the form"
- "Potential hardcoded credentials"
- "Use of weak random number generator"
- "xerrors.* is deprecated"
# gosec
- "^G101: Potential hardcoded credentials"
- "^G108: Profiling endpoint is automatically exposed on /debug/pprof"
- "^G204: Subprocess launched with (variable|a potential tainted input or cmd arguments)"
- "^G301: Expect directory permissions to be 0750 or less"
- "^G302: Expect file permissions to be 0600 or less"
- "^G304: Potential file inclusion via variable"
- "^G306: Expect WriteFile permissions to be 0600 or less"
- "^G404: Use of weak random number generator"
# staticcheck
- "^SA1019: xerrors.* is deprecated: As of Go 1.13, use errors"
# revive
- "^blank-imports: a blank import should be only in a main or test package, or have a comment justifying it"
- "^dot-imports: should not use dot imports"
- "^exported: (func|type) name will be used as [^\\s]+ by other packages, and that stutters; consider calling this \\w+"
- "^exported: comment on exported (const|function|method|type|var) [^\\s]+ should be of the form \"\\w+ ...\""
- "^exported: exported (const|function|method|type|var) [^\\s]+ should have comment (\\(or a comment on this block\\) )?or be unexported"
- "^indent-error-flow: if block ends with a return statement, so drop this else and outdent its block \\(move short variable declaration to its own line if necessary\\)"
- "^package-comments: package comment should be of the form \"Package \\w+ ...\""
- "^package-comments: should have a package comment"
- "^unexported-return: exported func \\w+ returns unexported type [^\\s]+, which can be annoying to use"
- "^unused-parameter: parameter '\\w+' seems to be unused, consider removing or renaming it as _"
- "^var-naming: (const|func|type|var|struct field|(method|func|interface method) parameter) [A-Z]\\w+ should be"
- "^var-naming: (method|range var) \\w*(Api|Http|Id|Rpc|Url)[^\\s]* should be \\w*(API|HTTP|ID|RPC|URL)"
- "^var-naming: don't use underscores in Go names"
- "^var-naming: don't use ALL_CAPS in Go names; use CamelCase"

exclude-use-default: false
exclude-rules:

- path: node/modules/lp2p
linters:
- golint

- path: build/params_.*\.go
linters:
- golint

- path: api/apistruct/struct.go
linters:
- golint

- path: .*_test.go
linters:
- gosec
Expand All @@ -67,12 +63,3 @@ issues:
- path: cmd/lotus-bench/.*
linters:
- gosec

- path: api/test/.*
text: "context.Context should be the first parameter"
linters:
- golint

linters-settings:
goconst:
min-occurrences: 6
6 changes: 2 additions & 4 deletions blockstore/buffered.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ func (bs *BufferedBlockstore) DeleteMany(ctx context.Context, cids []cid.Cid) er

func (bs *BufferedBlockstore) View(ctx context.Context, c cid.Cid, callback func([]byte) error) error {
// both stores are viewable.
if err := bs.write.View(ctx, c, callback); ipld.IsNotFound(err) {
// not found in write blockstore; fall through.
} else {
if err := bs.write.View(ctx, c, callback); !ipld.IsNotFound(err) {
return err // propagate errors, or nil, i.e. found.
}
} // else not found in write blockstore; fall through.
return bs.read.View(ctx, c, callback)
}

Expand Down
4 changes: 2 additions & 2 deletions blockstore/splitstore/splitstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ func Open(path string, ds dstore.Datastore, hot, cold bstore.Blockstore, cfg *Co
if ss.checkpointExists() {
log.Info("found compaction checkpoint; resuming compaction")
if err := ss.completeCompaction(); err != nil {
markSetEnv.Close() //nolint:errcheck
_ = markSetEnv.Close()
return nil, xerrors.Errorf("error resuming compaction: %w", err)
}
}
if ss.pruneCheckpointExists() {
log.Info("found prune checkpoint; resuming prune")
if err := ss.completePrune(); err != nil {
markSetEnv.Close() //nolint:errcheck
_ = markSetEnv.Close()
return nil, xerrors.Errorf("error resuming prune: %w", err)
}
}
Expand Down
7 changes: 2 additions & 5 deletions blockstore/splitstore/splitstore_compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,13 @@ func (s *SplitStore) HeadChange(_, apply []*types.TipSet) error {
// TODO: ok to use hysteresis with no transitions between 30s and 1m?
if time.Since(timestamp) < SyncWaitTime {
/* Chain in sync */
if atomic.CompareAndSwapInt32(&s.outOfSync, 0, 0) {
// already in sync, no signaling necessary
} else {
if !atomic.CompareAndSwapInt32(&s.outOfSync, 0, 0) {
// transition from out of sync to in sync
s.chainSyncMx.Lock()
s.chainSyncFinished = true
s.chainSyncCond.Broadcast()
s.chainSyncMx.Unlock()
}

} // else already in sync, no signaling necessary
}
// 2. protect the new tipset(s)
s.protectTipSets(apply)
Expand Down
2 changes: 1 addition & 1 deletion blockstore/splitstore/splitstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
CompactionBoundary = 2
WarmupBoundary = 0
SyncWaitTime = time.Millisecond
logging.SetLogLevel("splitstore", "DEBUG")
_ = logging.SetLogLevel("splitstore", "DEBUG")
}

func testSplitStore(t *testing.T, cfg *Config) {
Expand Down
2 changes: 1 addition & 1 deletion build/builtin_actors_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/ipfs/go-cid"
)

var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMetadata{{
var EmbeddedBuiltinActorsMetadata = []*BuiltinActorsMetadata{{
Network: "butterflynet",
Version: 8,

Expand Down
2 changes: 1 addition & 1 deletion build/params_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,5 @@ const BootstrapPeerThreshold = 4
// As per https://github.com/ethereum-lists/chains
const Eip155ChainId = 314

// we skip checks on message validity in this block to sidestep the zero-bls signature
// WhitelistedBlock skips checks on message validity in this block to sidestep the zero-bls signature
var WhitelistedBlock = MustParseCid("bafy2bzaceapyg2uyzk7vueh3xccxkuwbz3nxewjyguoxvhx77malc2lzn2ybi")
1 change: 1 addition & 0 deletions build/params_shared_vals.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const MinimumBaseFee = 100
const PackingEfficiencyNum = 4
const PackingEfficiencyDenom = 5

// revive:disable-next-line:exported
// Actor consts
// TODO: pieceSize unused from actors
var MinDealDuration, MaxDealDuration = policy.DealDurationBounds(0)
6 changes: 2 additions & 4 deletions chain/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,7 @@ func (mp *MessagePool) Add(ctx context.Context, m *types.SignedMessage) error {
_, _ = mp.getStateNonce(ctx, m.Message.From, tmpCurTs)

mp.curTsLk.Lock()
if tmpCurTs == mp.curTs {
//with the lock enabled, mp.curTs is the same Ts as we just had, so we know that our computations are cached
} else {
if tmpCurTs != mp.curTs {
//curTs has been updated so we want to cache the new one:
tmpCurTs = mp.curTs
//we want to release the lock, cache the computations then grab it again
Expand All @@ -789,7 +787,7 @@ func (mp *MessagePool) Add(ctx context.Context, m *types.SignedMessage) error {
_, _ = mp.getStateNonce(ctx, m.Message.From, tmpCurTs)
mp.curTsLk.Lock()
//now that we have the lock, we continue, we could do this as a loop forever, but that's bad to loop forever, and this was added as an optimization and it seems once is enough because the computation < block time
}
} // else with the lock enabled, mp.curTs is the same Ts as we just had, so we know that our computations are cached

defer mp.curTsLk.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions chain/messagepool/selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand, getPremium fu
mustAdd(t, mp, m)
}

logging.SetLogLevel("messagepool", "error")
_ = logging.SetLogLevel("messagepool", "error")

// 1. greedy selection
gm, err := mp.selectMessagesGreedy(context.Background(), ts, ts)
Expand Down Expand Up @@ -1414,7 +1414,7 @@ func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand, getPremium fu
t.Logf("Average reward boost: %f", rewardBoost)
t.Logf("Average best tq reward: %f", totalBestTQReward/runs/1e12)

logging.SetLogLevel("messagepool", "info")
_ = logging.SetLogLevel("messagepool", "info")

return capacityBoost, rewardBoost, totalBestTQReward / runs / 1e12
}
Expand Down
3 changes: 1 addition & 2 deletions chain/rand/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ func (sr *stateRand) GetBeaconRandomness(ctx context.Context, filecoinEpoch abi.
return sr.getBeaconRandomnessV3(ctx, filecoinEpoch)
} else if nv == network.Version13 {
return sr.getBeaconRandomnessV2(ctx, filecoinEpoch)
} else {
return sr.getBeaconRandomnessV1(ctx, filecoinEpoch)
}
return sr.getBeaconRandomnessV1(ctx, filecoinEpoch)
}

func (sr *stateRand) DrawChainRandomness(ctx context.Context, pers crypto.DomainSeparationTag, filecoinEpoch abi.ChainEpoch, entropy []byte) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion chain/store/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func (s *walkScheduler) Wait() error {
log.Errorw("error writing to CAR file", "error", err)
return errWrite
}
s.workerTasks.Close() //nolint:errcheck
_ = s.workerTasks.Close()
return err
}

Expand Down
3 changes: 2 additions & 1 deletion chain/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ func (cs *ChainStore) SubHeadChanges(ctx context.Context) chan []*api.HeadChange
// Unsubscribe.
cs.bestTips.Unsub(subch)

// revive:disable-next-line:empty-block
// Drain the channel.
for range subch {
}
Expand Down Expand Up @@ -752,7 +753,7 @@ func FlushValidationCache(ctx context.Context, ds dstore.Batching) error {
for _, k := range allKeys {
if strings.HasPrefix(k.Key, blockValidationCacheKeyPrefix.String()) {
delCnt++
batch.Delete(ctx, dstore.RawKey(k.Key)) // nolint:errcheck
_ = batch.Delete(ctx, dstore.RawKey(k.Key))
}
}

Expand Down
4 changes: 2 additions & 2 deletions chain/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type syncTestUtil struct {
}

func prepSyncTest(t testing.TB, h int) *syncTestUtil {
logging.SetLogLevel("*", "INFO")
_ = logging.SetLogLevel("*", "INFO")

g, err := gen.NewGenerator()
if err != nil {
Expand Down Expand Up @@ -115,7 +115,7 @@ func prepSyncTest(t testing.TB, h int) *syncTestUtil {
}

func prepSyncTestWithV5Height(t testing.TB, h int, v5height abi.ChainEpoch) *syncTestUtil {
logging.SetLogLevel("*", "INFO")
_ = logging.SetLogLevel("*", "INFO")

sched := stmgr.UpgradeSchedule{{
// prepare for upgrade.
Expand Down
2 changes: 1 addition & 1 deletion chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ func NewEthBlockNumberOrHashFromNumber(number EthUint64) EthBlockNumberOrHash {

func NewEthBlockNumberOrHashFromHexString(str string) (EthBlockNumberOrHash, error) {
// check if block param is a number (decimal or hex)
var num EthUint64 = 0
var num EthUint64
err := num.UnmarshalJSON([]byte(str))
if err != nil {
return NewEthBlockNumberOrHashFromNumber(0), err
Expand Down
7 changes: 2 additions & 5 deletions chain/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,16 @@ func (vm *LegacyVM) send(ctx context.Context, msg *types.Message, parent *Runtim
return nil, aerrors.Wrapf(err, "could not create account")
}
toActor = a
if vm.networkVersion <= network.Version3 {
// Leave the rt.Message as is
} else {
if vm.networkVersion > network.Version3 {
nmsg := Message{
msg: types.Message{
To: aid,
From: rt.Message.Caller(),
Value: rt.Message.ValueReceived(),
},
}

rt.Message = &nmsg
}
} // else leave the rt.Message as is
} else {
return nil, aerrors.Escalate(err, "getting actor")
}
Expand Down
2 changes: 1 addition & 1 deletion cli/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type BackupApiFn func(ctx *cli.Context) (BackupAPI, jsonrpc.ClientCloser, error)

func BackupCmd(repoFlag string, rt repo.RepoType, getApi BackupApiFn) *cli.Command {
var offlineBackup = func(cctx *cli.Context) error {
logging.SetLogLevel("badger", "ERROR") // nolint:errcheck
_ = logging.SetLogLevel("badger", "ERROR")

repoPath := cctx.String(repoFlag)
r, err := repo.NewFS(repoPath)
Expand Down
6 changes: 3 additions & 3 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func interactiveDeal(cctx *cli.Context) error {
cs := readline.NewCancelableStdin(afmt.Stdin)
go func() {
<-ctx.Done()
cs.Close() // nolint:errcheck
_ = cs.Close()
}()

rl := bufio.NewReader(cs)
Expand Down Expand Up @@ -2327,7 +2327,7 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann
for _, channel := range sendingChannels {
w.Write(toChannelOutput("Sending To", channel, verbose))
}
w.Flush(out) //nolint:errcheck
_ = w.Flush(out)

fmt.Fprintf(out, "\nReceiving Channels\n\n")
w = tablewriter.New(tablewriter.Col("ID"),
Expand All @@ -2341,7 +2341,7 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann
for _, channel := range receivingChannels {
w.Write(toChannelOutput("Receiving From", channel, verbose))
}
w.Flush(out) //nolint:errcheck
_ = w.Flush(out)
}

func channelStatusString(status datatransfer.Status) string {
Expand Down
3 changes: 1 addition & 2 deletions cli/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ func infoCmdAct(cctx *cli.Context) error {
if err != nil {
if strings.Contains(err.Error(), "actor not found") {
continue
} else {
return err
}
return err
}
mbLockedSum = big.Add(mbLockedSum, mbal.Locked)
mbAvailableSum = big.Add(mbAvailableSum, mbal.Escrow)
Expand Down
2 changes: 1 addition & 1 deletion cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import (
)

func init() {
logging.SetLogLevel("watchdog", "ERROR")
_ = logging.SetLogLevel("watchdog", "ERROR")
}
2 changes: 1 addition & 1 deletion cli/sending_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func printChecks(printer io.Writer, checkGroups [][]api.MessageCheckStatus, prot
func askUser(printer io.Writer, q string, def bool) bool {
var resp string
fmt.Fprint(printer, q)
fmt.Scanln(&resp)
_, _ = fmt.Scanln(&resp)
resp = strings.ToLower(resp)
if len(resp) == 0 {
return def
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-bench/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (c *CMD) startWorker(qpsTicker *time.Ticker) {

start := time.Now()

var statusCode int = 0
var statusCode int

arr := strings.Fields(c.cmd)

Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type Commit2In struct {
}

func main() {
logging.SetLogLevel("*", "INFO")
_ = logging.SetLogLevel("*", "INFO")

log.Info("Starting lotus-bench")

Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-bench/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (r *Reporter) Print(elapsed time.Duration, w io.Writer) {
return r.latencies[i] < r.latencies[j]
})

var totalLatency int64 = 0
var totalLatency int64
for _, latency := range r.latencies {
totalLatency += latency
}
Expand Down
Loading

0 comments on commit b3ac64c

Please sign in to comment.