Commit 099af135 authored by liuyuhang's avatar liuyuhang

Update lint.txt

parent 38cc12d5
查看当前模块lint命令:golint -set_exit_status plugin/... 查看当前模块lint命令:golint -set_exit_status plugin/...
1、结构体、变量、常量、函数注释,提示----- 1、结构体、变量、常量、函数注释,提示-----
warning: exported const HashSize should have comment or be unexported warning: exported const HashSize should have comment or be unexported
warning: exported var ManageX should have comment or be unexported warning: exported var ManageX should have comment or be unexported
(如果exported 则需要加注释) (如果exported 则需要加注释)
格式如下: 格式如下:
const ( const (
// KeyWalletPassKey ....... // KeyWalletPassKey .......
KeyWalletPassKey = "WalletPassKey" KeyWalletPassKey = "WalletPassKey"
) )
// CalcWalletPassKey ....... // CalcWalletPassKey .......
func CalcWalletPassKey() []byte { func CalcWalletPassKey() []byte {
return []byte(keyWalletPassKey) return []byte(keyWalletPassKey)
} }
2、函数注释不规范system/dapp/query.go:15:1:warning: comment on exported method DriverBase.GetTxsByAddr should be of the form "GetTxsByAddr ..." (golint) 2、函数注释不规范system/dapp/query.go:15:1:warning: comment on exported method DriverBase.GetTxsByAddr should be of the form "GetTxsByAddr ..." (golint)
需要改成上面1示例 需要改成上面1示例
3、不需要初始化,默认为零,提示-----should drop = 0 from declaration of var currentHeight; it is the zero value 3、不需要初始化,默认为零,提示-----should drop = 0 from declaration of var currentHeight; it is the zero value
var ( var (
currentHeight int64 = 0 currentHeight int64 = 0
currentIndex int64 = 0 currentIndex int64 = 0
) )
改为 改为
var ( var (
currentHeight int64 currentHeight int64
currentIndex int64 currentIndex int64
) )
4、if else 如下格式的return,不需要加else,直接return,提示-----warning: if block ends with a return statement, so drop this else and outdent its block (golint) 4、if else 如下格式的return,不需要加else,直接return,提示-----warning: if block ends with a return statement, so drop this else and outdent its block (golint)
if head == nil { if head == nil {
blockhight := chain.GetBlockHeight() blockhight := chain.GetBlockHeight()
tmpHead, err := chain.blockStore.GetBlockHeaderByHeight(blockhight) tmpHead, err := chain.blockStore.GetBlockHeaderByHeight(blockhight)
if err == nil && tmpHead != nil { if err == nil && tmpHead != nil {
chainlog.Error("ProcGetLastHeaderMsg from cache is nil.", "blockhight", blockhight, "hash", common.ToHex(tmpHead.Hash)) chainlog.Error("ProcGetLastHeaderMsg from cache is nil.", "blockhight", blockhight, "hash", common.ToHex(tmpHead.Hash))
return tmpHead, nil return tmpHead, nil
} else { } else {
return nil, err return nil, err
} }
} }
改为: 改为:
if head == nil { if head == nil {
blockhight := chain.GetBlockHeight() blockhight := chain.GetBlockHeight()
tmpHead, err := chain.blockStore.GetBlockHeaderByHeight(blockhight) tmpHead, err := chain.blockStore.GetBlockHeaderByHeight(blockhight)
if err == nil && tmpHead != nil { if err == nil && tmpHead != nil {
chainlog.Error("ProcGetLastHeaderMsg from cache is nil.", "blockhight", blockhight, "hash", common.ToHex(tmpHead.Hash)) chainlog.Error("ProcGetLastHeaderMsg from cache is nil.", "blockhight", blockhight, "hash", common.ToHex(tmpHead.Hash))
return tmpHead, nil return tmpHead, nil
} }
return nil, err return nil, err
} }
5、不出现this, self等参数,提示----- warning: receiver name should be a reflection of its identity; don't use generic names such as "this" or "self" 5、不出现this, self等参数,提示----- warning: receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"
func (this *UpdateInitFileTask) genInitFile() error {} func (this *UpdateInitFileTask) genInitFile() error {}
改为: 改为:
func (up *UpdateInitFileTask) genInitFile() error {} func (up *UpdateInitFileTask) genInitFile() error {}
6、使用自加格式, 提示-----warning: should replace resp.Actual += 1 with resp.Actual++ (golint) 6、使用自加格式, 提示-----warning: should replace resp.Actual += 1 with resp.Actual++ (golint)
7、函数名、变量不使用带下划线(我们chain33利用加下划线实现了一些功能,因此这个暂时不需要改), 提示-----warning: don't use underscores in Go names; method ExecDelLocal_Transfer should be ExecDelLocalTransfer (golint) 7、函数名、变量不使用带下划线(我们chain33利用加下划线实现了一些功能,因此这个暂时不需要改), 提示-----warning: don't use underscores in Go names; method ExecDelLocal_Transfer should be ExecDelLocalTransfer (golint)
8、实现接口方法,中前后形参要一致, 提示-----warning: receiver name store should be consistent with previous receiver name ws for walletStore (golint) 8、实现接口方法,中前后形参要一致, 提示-----warning: receiver name store should be consistent with previous receiver name ws for walletStore (golint)
func (ws *walletStore) SetFeeAmount(FeeAmount int64) error { func (ws *walletStore) SetFeeAmount(FeeAmount int64) error {
.... ....
return nil return nil
} }
func (store *walletStore) GetFeeAmount(minFee int64) int64 { func (store *walletStore) GetFeeAmount(minFee int64) int64 {
.... ....
return FeeAmount return FeeAmount
} }
改为: 改为:
func (ws *walletStore) SetFeeAmount(FeeAmount int64) error { func (ws *walletStore) SetFeeAmount(FeeAmount int64) error {
.... ....
return nil return nil
} }
func (ws *walletStore) GetFeeAmount(minFee int64) int64 { func (ws *walletStore) GetFeeAmount(minFee int64) int64 {
.... ....
return FeeAmount return FeeAmount
} }
9、errors.New(fmt.Sprintf(...)) 这种格式替换为fmt.Errorf(...), 提示-----warning: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (golint) 9、errors.New(fmt.Sprintf(...)) 这种格式替换为fmt.Errorf(...), 提示-----warning: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (golint)
index := strings.Index(context, this.ActionName) index := strings.Index(context, this.ActionName)
if index < 0 { if index < 0 {
return errors.New(fmt.Sprintf("Action %s Not Existed", this.ActionName)) return errors.New(fmt.Sprintf("Action %s Not Existed", this.ActionName))
} }
改为: 改为:
index := strings.Index(context, this.ActionName) index := strings.Index(context, this.ActionName)
if index < 0 { if index < 0 {
return fmt.Errorf("Action %s Not Existed", this.ActionName) return fmt.Errorf("Action %s Not Existed", this.ActionName)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment