美文网首页云计算
Go代码检查工具--增强版

Go代码检查工具--增强版

作者: 沙漠中的猴 | 来源:发表于2018-10-30 16:44 被阅读395次
package main

import "os"

func main(){
    f, _ := os.Open("main.go")
    defer f.Close()
}

上面代码有什么问题吗?
当我们执行go build的时候,发现并没有报错。

简介

gometalinter工具可以检查Go代码中一些隐蔽的错误。go的编译器有的时候仅仅是能检查语法层面的错误,而不能检测出逻辑的错误。所以就需要一些额外的错误检查工具来进行代码检测。

地址

github.com/alecthomas/gometalinter

安装方式

go get -u -x github.com/alecthomas/gometalinter

可以看到下载的内容,以及更新安装包。

root@000d3fada0b3:~/go/src# gometalinter --install
Installing:
  deadcode
  dupl
  errcheck
  gochecknoglobals
  gochecknoinits
  goconst
  gocyclo
  goimports
  golint
  gosec
  gosimple
  gotype
  gotypex
  ineffassign
  interfacer
  lll
  maligned
  megacheck
  misspell
  nakedret
  safesql
  staticcheck
  structcheck
  unconvert
  unparam
  unused
  varcheck

上面的内容都是该工具中包含的插件。我们在代码目录执行该工具

root@000d3fada0b3:~/go/src# gometalinter
main.go:7:15:warning: error return value not checked (defer f.Close()) (errcheck)

会提示你,第7行错误返回没有检查。

有些时候这些工具会减少你写代码的出错概率。

相关文章

  • Go代码检查工具--增强版

    上面代码有什么问题吗?当我们执行go build的时候,发现并没有报错。 简介 gometalinter工具可以检...

  • Go Vet 常见warning总结

    go vet是一个用于检查Go语言源码中静态错误的简单工具,消灭go vet扫描出的静态错误,有利于提高代码质量和...

  • 2021-04-13

    介绍: Clang-tidy工具是基于Clang的代码检查工具(linter).代码检查工具一般负责分析代码并找出...

  • Golang goland idea+golint+go fmt

    一、Go的相关插件工具简介 golint 代码的风格检测 go fmt 重新格式化Go源代码 goimports ...

  • 使用注解改进代码检查

    使用注解改进代码检查[摘抄官网] 使用代码检查工具(例如 Lint)可以帮助您找到问题并改进代码,不过,检查工具只...

  • Learn C the Hard Way Ex4:Using a

    c语言代码检查工具:splintLinux 内存泄漏检查工具:Valgrindmac 内存泄漏检查工具:Addre...

  • Golang压力测试

    Go Test工具 Go语言中的测试依赖go test命令。编写测试代码和编写普通的Go代码过程是类似的,并不需要...

  • Goland辅助工具goimports和gomodules

    1、goimports工具 goimports工具是Go官方提供的一种工具,它能够为我们自动格式化 Go 语言代码...

  • iOS Code Review - Objective-C代码静

    Code Review 代码评审,代码静态检查,Objective-C代码静态检查工具——OCLint Githu...

  • go 的代码静态检查工具 golangci-lint

    golangci-lint[https://github.com/golangci/golangci-lint] ...

网友评论

    本文标题:Go代码检查工具--增强版

    本文链接:https://www.haomeiwen.com/subject/cweknftx.html