mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
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:
parent
db5f4fb3fe
commit
5470fc668b
@ -11,19 +11,24 @@ linters:
|
|||||||
- contextcheck
|
- contextcheck
|
||||||
- decorder
|
- decorder
|
||||||
- dogsled
|
- dogsled
|
||||||
|
- dupl
|
||||||
- dupword
|
- dupword
|
||||||
- durationcheck
|
- durationcheck
|
||||||
- errcheck
|
- errcheck
|
||||||
- errchkjson
|
- errchkjson
|
||||||
- errname
|
- errname
|
||||||
|
- errorlint
|
||||||
- execinquery
|
- execinquery
|
||||||
|
- exhaustive
|
||||||
- exportloopref
|
- exportloopref
|
||||||
- forbidigo
|
- forbidigo
|
||||||
|
- forcetypeassert
|
||||||
- ginkgolinter
|
- ginkgolinter
|
||||||
- gocheckcompilerdirectives
|
- gocheckcompilerdirectives
|
||||||
- gochecksumtype
|
- gochecksumtype
|
||||||
- gocognit
|
- gocognit
|
||||||
- goconst
|
- goconst
|
||||||
|
- gocritic
|
||||||
- gocyclo
|
- gocyclo
|
||||||
- gofmt
|
- gofmt
|
||||||
- goheader
|
- goheader
|
||||||
@ -71,12 +76,12 @@ linters-settings:
|
|||||||
max-func-lines: 100
|
max-func-lines: 100
|
||||||
issues:
|
issues:
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
- path: codec\.go
|
- path: x/.*/types/message.*\.go
|
||||||
linters:
|
linters:
|
||||||
- nosnakecase
|
- dupl
|
||||||
- path: app\/simulation_test\.go
|
- path: x/dao/client/cli/tx_reissue_rddl.*\.go
|
||||||
linters:
|
linters:
|
||||||
- nosnakecase
|
- dupl
|
||||||
- path: testutil\/rest\.go
|
- path: testutil/nullify/nullify\.go
|
||||||
linters:
|
linters:
|
||||||
- nosnakecase
|
- exhaustive
|
||||||
|
@ -112,7 +112,10 @@ func initRootCmd(
|
|||||||
// Set config
|
// Set config
|
||||||
initSDKConfig()
|
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(
|
rootCmd.AddCommand(
|
||||||
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
|
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
|
||||||
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, gentxModule.GenTxValidator),
|
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, gentxModule.GenTxValidator),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
@ -13,12 +14,10 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
rootCmd, _ := cmd.NewRootCmd()
|
rootCmd, _ := cmd.NewRootCmd()
|
||||||
if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil {
|
if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil {
|
||||||
switch e := err.(type) {
|
var e *server.ErrorCode
|
||||||
case server.ErrorCode:
|
if errors.As(err, &e) {
|
||||||
os.Exit(e.Code)
|
os.Exit(e.Code)
|
||||||
|
|
||||||
default:
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func New(t *testing.T, configs ...Config) *Network {
|
|||||||
}
|
}
|
||||||
validatorTmpDir := t.TempDir()
|
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 := config.GetConfig()
|
||||||
appConfig.SetRoot(validatorTmpDir + "/node0/simd")
|
appConfig.SetRoot(validatorTmpDir + "/node0/simd")
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ func buildSignBroadcastTx(goCtx context.Context, sendingValidatorAddress string,
|
|||||||
|
|
||||||
func InitRDDLReissuanceProcess(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64) (err error) {
|
func InitRDDLReissuanceProcess(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64) (err error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
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()
|
logger := ctx.Logger()
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
||||||
logger.Debug("REISSUE: create Reissuance Proposal")
|
logger.Debug("REISSUE: create Reissuance Proposal")
|
||||||
|
@ -65,10 +65,10 @@ func getLastPopBytes(height int64) []byte {
|
|||||||
return big.NewInt(height + 1).Bytes()
|
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()
|
conf := config.GetConfig()
|
||||||
distribution.FirstPop = lastReissuance
|
distribution.FirstPop = lastReissuance
|
||||||
distribution.LastPop = BlockHeight
|
distribution.LastPop = blockHeight
|
||||||
|
|
||||||
distribution.DaoAddr = conf.DistributionAddrDAO
|
distribution.DaoAddr = conf.DistributionAddrDAO
|
||||||
distribution.InvestorAddr = conf.DistributionAddrInv
|
distribution.InvestorAddr = conf.DistributionAddrInv
|
||||||
@ -105,11 +105,11 @@ func (k Keeper) GetDistributionForReissuedTokens(ctx sdk.Context, blockHeight in
|
|||||||
reissuances := k.getReissuancesRange(ctx, lastPoP)
|
reissuances := k.getReissuancesRange(ctx, lastPoP)
|
||||||
var overallAmount uint64
|
var overallAmount uint64
|
||||||
for index, obj := range reissuances {
|
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) {
|
(lastPoP < obj.BlockHeight && obj.BlockHeight <= blockHeight) {
|
||||||
amount, err := getUint64FromTxString(ctx, obj.Rawtx)
|
amount, err := getUint64FromTxString(ctx, obj.Rawtx)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
overallAmount = overallAmount + amount
|
overallAmount += amount
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Logger().Info("%u %u %u", lastPoP, obj.BlockHeight, blockHeight)
|
ctx.Logger().Info("%u %u %u", lastPoP, obj.BlockHeight, blockHeight)
|
||||||
|
@ -21,7 +21,7 @@ func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReis
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
// 3. notarize result by notarizing the liquid tx-id
|
// 3. notarize result by notarizing the liquid tx-id
|
||||||
_ = util.SendRDDLReissuanceResult(goCtx, msg.GetProposer(), txID, msg.GetBlockHeight())
|
_ = util.SendRDDLReissuanceResult(goCtx, msg.GetProposer(), txID, msg.GetBlockHeight())
|
||||||
//TODO verify and resolve error
|
// TODO verify and resolve error
|
||||||
} else {
|
} else {
|
||||||
logger.Error("REISSUE: Asset reissuance failure: " + err.Error())
|
logger.Error("REISSUE: Asset reissuance failure: " + err.Error())
|
||||||
}
|
}
|
||||||
|
@ -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
|
// TODO: ensuer issuePoPrewards is only called once per PoP on all validators
|
||||||
func (k msgServer) issuePoPRewards(_ types.Challenge) (err error) {
|
func (k msgServer) issuePoPRewards(_ types.Challenge) (err error) {
|
||||||
//cfg := config.GetConfig()
|
// cfg := config.GetConfig()
|
||||||
//client := osc.NewClient(cfg.WatchmenEndpoint, 1234)
|
// client := osc.NewClient(cfg.WatchmenEndpoint, 1234)
|
||||||
|
|
||||||
// TODO: finalize message and endpoint
|
// TODO: finalize message and endpoint
|
||||||
//msg := osc.NewMessage("/rddl/token")
|
// msg := osc.NewMessage("/rddl/token")
|
||||||
//msg.Append(challenge.Challenger)
|
// msg.Append(challenge.Challenger)
|
||||||
//msg.Append(challenge.Challengee)
|
// msg.Append(challenge.Challengee)
|
||||||
//err := client.Send(msg)
|
// err := client.Send(msg)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
if k.isNFTCreationRequest(msg.Machine) && util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) {
|
||||||
_ = k.issueMachineNFT(ctx, msg.Machine)
|
_ = 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 {
|
// if err != nil {
|
||||||
// return nil, types.ErrNFTIssuanceFailed
|
// 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)
|
_, _, err := k.issueNFTAsset(ctx, machine.Name, machine.Address)
|
||||||
return err
|
return err
|
||||||
// asset registration is not performed in case of NFT issuance for machines
|
// 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 {
|
// if err != nil {
|
||||||
// return err
|
// return err
|
||||||
// }
|
// }
|
||||||
//return k.registerAsset(assetID, contract)
|
// return k.registerAsset(assetID, contract)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user