Golint
golint
不同于go fmt
,用于检测代码的规范性。
一、用法
Usage of golint:
golint [flags] # runs on package in current directory
golint [flags] [packages]
golint [flags] [directories] # where a '/...' suffix includes all sub-directories
golint [flags] [files] # all must belong to a single package
Flags:
-min_confidence float
minimum confidence of a problem to print it (default 0.8)
-set_exit_status
set exit status to 1 if any issues are found
考虑以下代码:
func GetSelectedDeviceIndex() []int {
for {
log.Println("Select Target Device: ")
index, err := utils.ScanlnInteger()
if err == nil {
return utils.UniqueIntegerArray(index)
}
else {
log.Println("Invalid Input!")
}
}
}
在使用golint
后,就会返回if block ends with a return statement, so drop this else and outdent its block
的提示,需要做出如下改动:
func GetSelectedDeviceIndex() []int {
for {
log.Println("Select Target Device: ")
index, err := utils.ScanlnInteger()
if err == nil {
return utils.UniqueIntegerArray(index)
}
log.Println("Invalid Input!")
}
}
二、Goland集成golint
点击
Files->Settings->Tools->File Watcher
,并点击+
,选择custom
。填入golint的位置和参数,并根据需求选择
advanced options
。
Last updated
Was this helpful?