Improve linter setup (#185)

* [linter] Remove unused exclusions

Linter `nosnakecase` was removed in 1e1138d0268a9896a1bd058e9b65b808eb20666e.

* [linter] Add tool for code clone detection

* [linter] Add `errorlint`

Find code that will cause problems with the error wrapping scheme
introduced in Go 1.13.

* [linter] Add `exhaustive`

Check exhaustiveness of enum switch statements.

* [linter] Add `forcetypeassert`

Finds type assertions which did forcely such as below:
```
func f() {
	var a interface{}
	_ = a.(int) // type assertion must be checked
}
```

* [linter] Add `gocritic`

Provides diagnostics that check for bugs, performance and style issues.

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2023-11-16 17:44:38 +01:00 committed by GitHub
parent db5f4fb3fe
commit 5470fc668b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 28 deletions

View File

@ -11,19 +11,24 @@ linters:
- contextcheck
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- ginkgolinter
- gocheckcompilerdirectives
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- goheader
@ -71,12 +76,12 @@ linters-settings:
max-func-lines: 100
issues:
exclude-rules:
- path: codec\.go
- path: x/.*/types/message.*\.go
linters:
- nosnakecase
- path: app\/simulation_test\.go
- dupl
- path: x/dao/client/cli/tx_reissue_rddl.*\.go
linters:
- nosnakecase
- path: testutil\/rest\.go
- dupl
- path: testutil/nullify/nullify\.go
linters:
- nosnakecase
- exhaustive

View File

@ -112,7 +112,10 @@ func initRootCmd(
// Set config
initSDKConfig()
gentxModule := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)
gentxModule, ok := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)
if !ok {
panic("forced type assertion failed for gentxModule")
}
rootCmd.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, gentxModule.GenTxValidator),

View File

@ -1,6 +1,7 @@
package main
import (
"errors"
"os"
"github.com/cosmos/cosmos-sdk/server"
@ -13,12 +14,10 @@ import (
func main() {
rootCmd, _ := cmd.NewRootCmd()
if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil {
switch e := err.(type) {
case server.ErrorCode:
var e *server.ErrorCode
if errors.As(err, &e) {
os.Exit(e.Code)
default:
os.Exit(1)
}
os.Exit(1)
}
}

View File

@ -40,7 +40,7 @@ func New(t *testing.T, configs ...Config) *Network {
}
validatorTmpDir := t.TempDir()
//set the proper root dir for the test environment so that the abci.go logic works
// set the proper root dir for the test environment so that the abci.go logic works
appConfig := config.GetConfig()
appConfig.SetRoot(validatorTmpDir + "/node0/simd")

View File

@ -25,7 +25,7 @@ func buildSignBroadcastTx(goCtx context.Context, sendingValidatorAddress string,
func InitRDDLReissuanceProcess(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64) (err error) {
ctx := sdk.UnwrapSDKContext(goCtx)
//get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
// get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
logger := ctx.Logger()
sendingValidatorAddress := config.GetConfig().ValidatorAddress
logger.Debug("REISSUE: create Reissuance Proposal")

View File

@ -65,10 +65,10 @@ func getLastPopBytes(height int64) []byte {
return big.NewInt(height + 1).Bytes()
}
func ComputeDistribution(lastReissuance int64, BlockHeight int64, amount uint64) (distribution types.DistributionOrder) {
func ComputeDistribution(lastReissuance int64, blockHeight int64, amount uint64) (distribution types.DistributionOrder) {
conf := config.GetConfig()
distribution.FirstPop = lastReissuance
distribution.LastPop = BlockHeight
distribution.LastPop = blockHeight
distribution.DaoAddr = conf.DistributionAddrDAO
distribution.InvestorAddr = conf.DistributionAddrInv
@ -105,11 +105,11 @@ func (k Keeper) GetDistributionForReissuedTokens(ctx sdk.Context, blockHeight in
reissuances := k.getReissuancesRange(ctx, lastPoP)
var overallAmount uint64
for index, obj := range reissuances {
if (index == 0 && lastPoP == 0 && obj.BlockHeight == 0) || //corner case (beginning of he chain)
if (index == 0 && lastPoP == 0 && obj.BlockHeight == 0) || // corner case (beginning of he chain)
(lastPoP < obj.BlockHeight && obj.BlockHeight <= blockHeight) {
amount, err := getUint64FromTxString(ctx, obj.Rawtx)
if err == nil {
overallAmount = overallAmount + amount
overallAmount += amount
}
} else {
ctx.Logger().Info("%u %u %u", lastPoP, obj.BlockHeight, blockHeight)

View File

@ -21,7 +21,7 @@ func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReis
if err == nil {
// 3. notarize result by notarizing the liquid tx-id
_ = util.SendRDDLReissuanceResult(goCtx, msg.GetProposer(), txID, msg.GetBlockHeight())
//TODO verify and resolve error
// TODO verify and resolve error
} else {
logger.Error("REISSUE: Asset reissuance failure: " + err.Error())
}

View File

@ -32,14 +32,14 @@ func (k msgServer) ReportPopResult(goCtx context.Context, msg *types.MsgReportPo
// TODO: ensuer issuePoPrewards is only called once per PoP on all validators
func (k msgServer) issuePoPRewards(_ types.Challenge) (err error) {
//cfg := config.GetConfig()
//client := osc.NewClient(cfg.WatchmenEndpoint, 1234)
// cfg := config.GetConfig()
// client := osc.NewClient(cfg.WatchmenEndpoint, 1234)
// TODO: finalize message and endpoint
//msg := osc.NewMessage("/rddl/token")
//msg.Append(challenge.Challenger)
//msg.Append(challenge.Challengee)
//err := client.Send(msg)
// msg := osc.NewMessage("/rddl/token")
// msg.Append(challenge.Challenger)
// msg.Append(challenge.Challengee)
// err := client.Send(msg)
return err
}

View File

@ -46,7 +46,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
if k.isNFTCreationRequest(msg.Machine) && util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) {
_ = k.issueMachineNFT(ctx, msg.Machine)
//TODO create NFTCreationMessage to be stored by all nodes
// TODO create NFTCreationMessage to be stored by all nodes
// if err != nil {
// return nil, types.ErrNFTIssuanceFailed
// }
@ -113,9 +113,9 @@ func (k msgServer) issueMachineNFT(ctx sdk.Context, machine *types.Machine) erro
_, _, err := k.issueNFTAsset(ctx, machine.Name, machine.Address)
return err
// asset registration is not performed in case of NFT issuance for machines
//assetID, contract, err := k.issueNFTAsset(machine.Name, machine.Address)
// assetID, contract, err := k.issueNFTAsset(machine.Name, machine.Address)
// if err != nil {
// return err
// }
//return k.registerAsset(assetID, contract)
// return k.registerAsset(assetID, contract)
}