确定要lint的package

go list -f '{{ .ImportPath }}' ./...

官方lint

这个功能相当强大,建议总是启用–enable-all
github

Usage of golint:golint [flags] # runs on package in current directorygolint [flags] [packages]golint [flags] [directories] # where a '/...' suffix includes all sub-directoriesgolint [flags] [files] # all must belong to a single package
Flags:-min_confidence floatminimum confidence of a problem to print it (default 0.8)-set_exit_statusset exit status to 1 if any issues are found

GolangCI-Lint

github

Smart, fast linters runner. Run it in cloud for every GitHub pull request on https://golangci.comUsage:golangci-lint [flags]golangci-lint [command]Available Commands:config      Confighelp        Helplinters     List current linters configurationrun         Run this tool in cloud on every github pull request in https://golangci.com for free (public repos)Flags:--color string              Use color when printing; can be 'always', 'auto', or 'never' (default "auto")-j, --concurrency int           Concurrency (default NumCPU) (default 8)--cpu-profile-path string   Path to CPU profile output file-h, --help                      help for golangci-lint--mem-profile-path string   Path to memory profile output file-v, --verbose                   verbose output--version                   Print versionUse "golangci-lint [command] --help" for more information about a command.

查看使用的linters

Enabled by your configuration linters:
deadcode: Finds unused code [fast: true, auto-fix: false]
errcheck: Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: true, auto-fix: false]
gosimple: Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
govet (vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
ineffassign: Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
staticcheck: Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
structcheck: Finds unused struct fields [fast: true, auto-fix: false]
typecheck: Like the front-end of a Go compiler, parses and type-checks Go code [fast: true, auto-fix: false]
unused: Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
varcheck: Finds unused global variables and constants [fast: true, auto-fix: false]Disabled by your configuration linters:
bodyclose: checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
depguard: Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
dupl: Tool for code clone detection [fast: true, auto-fix: false]
gochecknoglobals: Checks that no globals are present in Go code [fast: true, auto-fix: false]
gochecknoinits: Checks that no init functions are present in Go code [fast: true, auto-fix: false]
goconst: Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
gocritic: The most opinionated Go source code linter [fast: true, auto-fix: false]
gocyclo: Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
gofmt: Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]
golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false]
gosec (gas): Inspects source code for security problems [fast: true, auto-fix: false]
interfacer: Linter that suggests narrower interface types [fast: false, auto-fix: false]
lll: Reports long lines [fast: true, auto-fix: false]
maligned: Tool to detect Go structs that would take less memory if their fields were sorted [fast: true, auto-fix: false]
misspell: Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
nakedret: Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
prealloc: Finds slice declarations that could potentially be preallocated [fast: true, auto-fix: false]
scopelint: Scopelint checks for unpinned variables in go programs [fast: true, auto-fix: false]
stylecheck: Stylecheck is a replacement for golint [fast: false, auto-fix: false]
unconvert: Remove unnecessary type conversions [fast: true, auto-fix: false]
unparam: Reports unused function parameters [fast: false, auto-fix: false]

Pass -E/–enable to enable linter and -D/–disable to disable:

golangci-lint run --disable-all -E errcheck

各种配置

spread $golangci-lint run --help
Run this tool in cloud on every github pull request in https://golangci.com for free (public repos)Usage:golangci-lint run [flags]Flags:--out-format string           Format of output: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml (default "colored-line-number")--print-issued-lines          Print lines of code with issue (default true)--print-linter-name           Print linter name in issue line (default true)--issues-exit-code int        Exit code when issues were found (default 1)--build-tags strings          Build tags--deadline duration           Deadline for total work (default 1m0s)--tests                       Analyze tests (*_test.go) (default true)--print-resources-usage       Print avg and max memory usage of golangci-lint and total time-c, --config PATH                 Read config from file path PATH--no-config                   Don't read config--skip-dirs strings           Regexps of directories to skip--skip-files strings          Regexps of files to skip-E, --enable strings              Enable specific linter-D, --disable strings             Disable specific linter--enable-all                  Enable all linters--disable-all                 Disable all linters-p, --presets strings             Enable presets (bugs|complexity|format|performance|style|unused) of linters. Run 'golangci-lint linters' to see them. This option implies option --disable-all--fast                        Run only fast linters from enabled linters set (first run won't be fast)-e, --exclude strings             Exclude issue by regexp--exclude-use-default         Use or not use default excludes:# errcheck: Almost all programs ignore errors on these functions and in most cases it's ok- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked# golint: Annoying issue about not having a comment. The rare codebase has such comments- (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form)# golint: False positive when tests are defined in package 'test'- func name will be used as test\.Test.* by other packages, and that stutters; consider calling this# govet: Common false positives- (possible misuse of unsafe.Pointer|should have signature)# staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore- ineffective break statement. Did you mean to break out of the outer loop# gosec: Too many false-positives on 'unsafe' usage- Use of unsafe calls should be audited# gosec: Too many false-positives for parametrized shell calls- Subprocess launch(ed with variable|ing should be audited)# gosec: Duplicated errcheck checks- G104# gosec: Too many issues in popular repos- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)# gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'- Potential file inclusion via variable(default true)--max-issues-per-linter int   Maximum issues count per one linter. Set to 0 to disable (default 50)--max-same-issues int         Maximum count of issues with the same text. Set to 0 to disable (default 3)-n, --new                         Show only new issues: if there are unstaged changes or untracked files, only those changes are analyzed, else only changes in HEAD~ are analyzed.It's a super-useful option for integration of golangci-lint into existing large codebase.It's not practical to fix all existing issues at the moment of integration: much better to not allow issues in new code.For CI setups, prefer --new-from-rev=HEAD~, as --new can skip linting the current patch if any scripts generate unstaged files before golangci-lint runs.--new-from-rev REV            Show only new issues created after git revision REV--new-from-patch PATH         Show only new issues created in git patch with file path PATH--fix                         Fix found issues (if it's supported by the linter)-h, --help                        help for run

配置文件:
.golangci.yml
.golangci.toml
.golangci.json

awesome-go

没事多去看看这个,找工具

golang lint相关推荐

  1. 借助码云快速安装 golang.org/x/lint/golint 和 golang.org/x/tools/ 等依赖

    GO基本开发环境搭建 入门时使用VSCode是比较方便的, VSCode 会推荐我们安装如下工具 tools 工具集 guru golang.org/x/tools/cmd/guru gorename ...

  2. golang.org/x/lint安装失败

    git clone https://github.com/golang/lint.git $GOPATH/src/golang.org/x/lint

  3. mac vscode 配置golang

    配置环境变量 打开terminal 1 cd ~进入用户主目录, 2 ls -all查看是否存在.bash_profile 3 vim .bash_profile打开并编辑该文件 4 根据自己的实际情 ...

  4. Linux下golang开发环境搭建

    对于golang开发来说,Windows下可以用vscode或者liteide都不错,但是Linux下的开发也就只有vim了,所以怎么搞笑的利用vim进行golang开发呢? 参考官方推荐的一个插件: ...

  5. Golang开发环境搭建-Vim篇

    Golang开发环境搭建-Vim篇 转自:http://tonybai.com/2014/11/07/golang-development-environment-for-vim/ 虽说sublime ...

  6. vs code golang插件记录

    首先推荐一下两个网址: 比较不错的博客:http://www.cnblogs.com/zsy/p/5223957.html 在下载代码时,golang.org/x/tools代码下载不了,可以使用ht ...

  7. Windows下visual studio code搭建golang开发环境

    前言 其实环境搭建没什么难的,但是遇到一些问题,主要是有些网站资源访问不了(如:golang.org), 导致一些包无法安装,最终会导致环境搭建失败,跟据这个教程几步,我们将可以快速的构建golang ...

  8. 下载 golang.org/x 包出错不用代理的解决办法

    原文链接:https://www.jianshu.com/p/6fe61053c8aa?utm_campaign=maleskine&utm_content=note&utm_medi ...

  9. golang select default continue_Golang+VSCode环境配置

    安装golang.git golang官网下载Go语言安装包,安装.默认在 C:Go 官网下载git,安装.默认在C:Program FilesGit 配置环境变量 用户环境变量 新建 GOBIN 值 ...

最新文章

  1. linux cp 强制覆盖_Linux基本操作教程
  2. linux云自动化运维基础知识23(DNS服务)
  3. python开发的优秀界面-tkinter python(图形开发界面)
  4. 胆战心惊形容什么_阿里员工感慨:加班累死累活,还胆战心惊,难道IT公司都这个样?...
  5. Linux 中断处理浅析
  6. 【本周面试题】第5周 - 开发工具相关
  7. [置顶] 状态压缩DP 简单入门题 11题
  8. 【HDU - 1968】【UVA - 12096】The SetStack Computer (模拟,集合求交集并集操作,STL实现)
  9. 一个API接口的例子,包括单元测试
  10. 【英语学习】【English L06】U03 House L1 What type of apartment do you want to rent?
  11. Ubunt更换阿里云镜像源
  12. axure如何实现跳转_Axure 9 教程:如何做跑马灯广告、弹幕
  13. 麟龙指标通达信指标公式源码_【通达信】麟龙量能饱合度指标公式源码
  14. 企业邮箱哪个最好用?企业邮箱哪个安全?
  15. 网络计算机显示器接口,科普四种常见的电脑显示器连接线接口
  16. Not creating XLA devices, tf_xla_enable_xla_devices not set错误求助
  17. 安卓手机内置NFC模块的使用和开发
  18. 视频封装格式以及编码格式说明
  19. RFID叉车读写器在智能仓库收发货环节中的应用-铨顺宏
  20. 纵向冗余校验计算方法_常见校验算法

热门文章

  1. K均值(kmeans)分类
  2. 重新认识Windows计算器Calc(MatLab计算替代品)——你所不知道的细节
  3. 深信服网络挑战赛初赛_2019
  4. 电脑计算机快捷键消失,电脑桌面快捷方式不见了
  5. “疫情待业在家做跨境电商,两年全款买了房”:你看不起的行业,往往很赚钱...
  6. 学习秦始皇 五招打造无敌团队
  7. 虚拟主机怎么用?香港虚拟主机搭建网站教程
  8. sql语句练习题或面试题
  9. MFC应用程序设计(第二版)学习笔记
  10. 大漠多账号循环登录任务自动切换模板大漠绑定后台绑定游戏