go-critic

The most opinionated Go source code linter for code audit.

Github星跟蹤圖

go-critic

Build Status
Awesome
Go Report Card
coverage
PRs Welcome

Go source code linter providing checks currently missing from other linters.

Logo

There is never too much static code analysis. Try it out.

Documentation

The latest documentation is available at go-critic.github.io.

Installation

For most users, using go-critic under golangci-lint is enough.

Instructions below describe how to install "bare" go-critic.

If you don't have lintpack installed, do:

go get -v github.com/go-lintpack/lintpack/...

Get go-critic checkers:

go get -v github.com/go-critic/go-critic/...

After that, you can create gocritic binary by running:

cd $(go env GOPATH)/src/github.com/go-critic/go-critic &&
	make gocritic

Windows note: lintpack build might emit a warning. See https://github.com/go-critic/go-critic/issues/760.

Usage

Be sure gocritic executable is under your $PATH.

Usage of gocritic: gocritic [sub-command] [sub-command args...]
Run gocritic without arguments to get help output.

Supported sub-commands:
	check - run linter over specified targets
		$ gocritic check -help
		$ gocritic check -v -enable='paramTypeCombine,unslice' strings bytes
		$ gocritic check -v -enable='#diagnostic' -disable='#experimental,#opinionated' ./...
	version - print linter version
		$ gocritic version
	doc - get installed checkers documentation
		$ gocritic doc -help
		$ gocritic doc
		$ gocritic doc checkerName

check sub-command examples:

# Runs all stable checkers on `fmt` package:
gocritic check fmt

# Run all stable checkers on `pkg1` and `pkg2`
gocritic check pkg1 pkg2

# Runs specified checkers on `fmt` package:
gocritic check -enable elseif,paramName fmt

# Run all stable checkers on current dir and all its children recursively:
gocritic check ./...

# Like above, but without `appendAssign` check:
gocritic check -disable=appendAssign ./...

# Run all stable checkers on `foo.go` file
gocritic check foo.go

# Run stable diagnostics over `string` package
gocritic check -enable='#diagnostic' -disable='#experimental' string

In place of a single name, tag can be used. Tag is a named checkers group.

Tags:

  • #diagnostic - kind of checks that detect various errors in code
  • #style - kind of checks that find style issues in code
  • #performance - kind of checks that detect potential performance issues in code
  • #experimental - check is under testing and development. Disabled by default
  • #opinionated - check can be unwanted for some people. Disabled by default

Contributing

This project aims to be contribution-friendly.

Our chats: English or
Russian
(Telegram website)

We're using an optimistic merging strategy most of the time.
In short, this means that if your contribution has some flaws, we can still merge it and then
fix them by ourselves. Experimental and work-in-progress checkers are isolated, so nothing bad will happen.

Code style is the same as in Go project, see CodeReviewComments.

See CONTRIBUTING.md for more details.
It also describes how to develop a new checker for the linter.

主要指標

概覽
名稱與所有者go-critic/go-critic
主編程語言Go
編程語言Go (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2018-05-05 09:17:26
推送於2025-04-13 09:59:24
最后一次提交2025-04-13 11:59:22
發布數37
最新版本名稱v0.13.0 (發布於 )
第一版名稱v0.3.4 (發布於 )
用户参与
星數1.9k
關注者數23
派生數125
提交數833
已啟用問題?
問題數604
打開的問題數125
拉請求數804
打開的拉請求數6
關閉的拉請求數71
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?