Which linters do you use?

agolangf · 2018-03-16 15:30:12 · 660 次点击    
这是一个分享于 2018-03-16 15:30:12 的资源,其中的信息可能已经有所发展或是发生改变。


评论:

arp242:

I run these in my editor, as they're reasonably fast:

--enable=vet
--enable=errcheck
--enable=golint
--enable=ineffassign
--enable=goimports
--enable=lll --line-length=120

I run these on CI for most projects. They're not fast enough to run in the editor, but still useful enough to catch the occasional issue:

--enable=varcheck
--enable=interfacer
--enable=unconvert
--enable=structcheck
--enable=megacheck
Bake_Jailey:

gometalinter --enable-all

I'm a madman.

dlsniper:

The problem is that some of those are useless, like gas, or produce too many false positives to be useful, like errorcheck.

I use GoLand, which has its own linters, but before commits I run go vet, golint, and megacheck.

Bake_Jailey:

All of that is true. I did say it was mad.

I usually disable gas, the sql checker, as well as the line length checker, plus extra filtering to deal with linters which descend into vendor without being asked.

I'm not so sure about false positives from errorcheck. If you mean errors from close functions, I'd rather handle those than not.

dlsniper:

Yes, but I'm sure nobody handles errors from fmt.Printf, for example.

Also your comment about disabling linters doesn't make sense since the previous comment says you enable them all...

Bake_Jailey:

I've never had gometalinter show me a warning for fmt, even with everything enabled.

And I guess "I'm a madman" wasn't a strong enough hint that my answer wasn't completely serious.

arp242:

produce too many false positives to be useful, like errorcheck.

errcheck doesn't give me that many problems? The most common cases are either Close() where you're doing a read-only operation, or some Write() calls. It's not that common. You can also easily disable it with:

defer f.Close() // nolint: errcheck

Or for an entire function:

// nolint: errcheck
func Foo() {
}

It's a bit ugly, but in the past we've had a lot of people ignoring error checks (especially in tests) which caused all sorts of issues.

mikolaj:

gometalinter with following linters: golint, gotype, deadcode

cs-guy:

go vet, golint, and megacheck


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

660 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传