The most opinionated Go source code linter for code audit.

Overview

go-critic

Build Status Awesome Go Report Card coverage PRs Welcome

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

Logo

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

Features

  • Almost 100 diagnostics that check for bugs, performance and style issues
  • Extensible without re-compilation with dynamic rules
  • Includes #opinionated checks with very strict and specific requirements
  • Self-documented: gocritic doc <checkname> gives a checker description

Documentation

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

Installation

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

Precompiled go-critic binaries can be found at releases page.

Instructions below show how to build go-critic from sources.

GO111MODULE=on go get -v -u github.com/go-critic/go-critic/cmd/gocritic

If the command above does not work, you can try cloning this repository under your GOPATH and run make gocritic.

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

# Run all stable checkers on `fmt` package and configure rangeExprCopy checker
gocritic check [email protected] 128 fmt

# 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 `strings` package:
gocritic check -enable='#diagnostic' -disable='#experimental' strings

# Run all stable and non-opinionated checks:
gocritic check -enableAll -disable='#experimental,#opinionated' ./src/...

To get a list of available checker parameters, run gocritic doc <checkerName>.

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
  • #security - kind of checks that find security issues in code

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.

Comments
  • Support generics for Go 1.18

    Support generics for Go 1.18

    Currently no one have verified does go-critic work with generics from Go 1.18. Probably we should invest time into that.

    See https://github.com/golang/go/issues/50558

    CC: @quasilyte

    opened by cristaloleg 20
  • all: figure-out project name and logo

    all: figure-out project name and logo

    kfulint is a working name, not a final one. When we know which name we like, it would be a time to find logo (or mascot).

    We may also want to rename organization.. For reasons. We also need a new organization that is dedicated for Go linter only.

    Proposed organization names:

    • Infrared October (repo/org infrared-october)
    • multilint (repo/org go-multilint)
    • critic, critique, gritic, critig, crigeek (repo/org with "go-" prefix)
    • adviser/advisor/advicer (repo/org with "go-" prefix)
    help wanted release blocker 
    opened by quasilyte 17
  • Should go-critic climb directories looking for ruleguard rules?

    Should go-critic climb directories looking for ruleguard rules?

    Coming back to this, I have set up a trivial demonstration of the problem(s): https://github.com/thockin/ruleguard-multi-modules

    There are errors in both subdir/file.go and submod/file.go.

    $ golangci-lint run
    subdir/file.go:6:2: ruleguard: prefer mynet.ParseIPSloppy() (gocritic)
    	net.ParseIP("foobar")
    	^
    

    but

    $ golangci-lint run ./submod/
    ERRO [linters context] typechecking error: main module (example.com/root) does not contain package example.com/root/submod
    

    I know this is a problem with Go's own handling of multi-repo. Try the usual workaround:

    $ cd submod/; golangci-lint run; cd - >/dev/null
    

    No output.

    $ cd submod/; golangci-lint -v  run; cd - >/dev/null
    INFO [config_reader] Config search paths: [./ /home/thockin/src/go/src/github.com/thockin/ruleguard-multi-modules/submod /home/thockin/src/go/src/github.com/thockin/ruleguard-multi-modules /home/thockin/src/go/src/github.com/thockin /home/thockin/src/go/src/github.com /home/thockin/src/go/src /home/thockin/src/go /home/thockin/src /home/thockin /home /] 
    INFO [config_reader] Used config file ../.golangci.yaml 
    INFO [lintersdb] Active 1 linters: [gocritic]     
    INFO [loader] Go packages loading at mode 575 (compiled_files|files|name|deps|exports_file|imports|types_sizes) took 70.889764ms 
    INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 94.267µs 
    INFO [linters context/goanalysis] analyzers took 0s with no stages 
    INFO [runner] processing took 3.34µs with stages: max_same_issues: 551ns, nolint: 523ns, skip_dirs: 257ns, cgo: 241ns, skip_files: 217ns, max_from_linter: 217ns, filename_unadjuster: 212ns, diff: 143ns, path_prettifier: 135ns, identifier_marker: 131ns, uniq_by_line: 130ns, autogenerated_exclude: 129ns, exclude: 124ns, max_per_file_from_linter: 53ns, path_shortener: 51ns, source_code: 50ns, sort_results: 49ns, severity-rules: 44ns, exclude-rules: 42ns, path_prefixer: 41ns 
    INFO [runner] linters took 16.305039ms with stages: gocritic: 16.238387ms 
    INFO File cache stats: 0 entries of total size 0B 
    INFO Memory: 2 samples, avg is 71.7MB, max is 71.8MB 
    INFO Execution took 92.837517ms                   
    

    It found the golangi-lint config in the parent dir, but not the rules file. But it didn't complain in any way, making me thing it actually passed, when it didn't.

    What would you think about go-critic ascending directories, looking for the rules file?

    Something like:

    --- a/go-critic/go-critic/checkers/ruleguard_checker.go
    +++ b/go-critic/go-critic/checkers/ruleguard_checker.go
    @@ -71,14 +71,32 @@ func newRuleguardChecker(info *linter.CheckerInfo, ctx *linter.CheckerContext) (
            }
     
            loaded := 0
    +       keepSearching := true
    +       prefix := ""
    +       for keepSearching {
    +               relnames := 0
                    for _, filePattern := range filePatterns {
    +                       if !filepath.IsAbs(filePattern) {
    +                               relnames++
    +                               filePattern = prefix + filePattern
    +                       }
                            filenames, err := filepath.Glob(strings.TrimSpace(filePattern))
                            if err != nil {
                                    // The only possible returned error is ErrBadPattern, when pattern is malformed.
                                    log.Printf("ruleguard init error: %+v", err)
    +                               keepSearching = false
    +                               continue
    +                       }
    +                       if len(filenames) > 0 {
    +                               // Any match stops the search.
    +                               keepSearching = false
    +                       } else {
    +                               // No match - ascend.
    +                               prefix += "../"
                                    continue
                            }
                            for _, filename := range filenames {
    +                               log.Printf("ruleguard init: reading rule file %s", filename)
                                    data, err := ioutil.ReadFile(filename)
                                    if err != nil {
                                            if failOnErrorFlag {
    @@ -97,6 +115,8 @@ func newRuleguardChecker(info *linter.CheckerInfo, ctx *linter.CheckerContext) (
                                    loaded++
                            }
                    }
    +       }
    +       log.Printf("ruleguard init: loaded %d rule files", loaded)
     
            if loaded != 0 {
                    c.engine = engine
    

    This still produces an error could not import github.com/quasilyte/go-ruleguard/dsl (can't find import: "github.com/quasilyte/go-ruleguard/dsl") but it feels like progress...

    opened by thockin 13
  • Error when trying to run

    Error when trying to run

    I am getting this error:

    [jacob@workstation fyne]$ ~/go/bin/gocritic check ./...
    panic: load embedded ruleguard rules: typechecker error: rules/rules.go:4:2: could not import github.com/quasilyte/go-ruleguard/dsl (can't find import: "github.com/quasilyte/go-ruleguard/dsl")
    

    I just installed using go install on my Fedora 34 and getting this error.

    opened by Jacalz 13
  • lint: return after fatal/panic

    lint: return after fatal/panic

    Detects return statements that follow panic/fatal logging.

    Before:

    log.Fatal("exits funciton")
    return
    

    After:

    log.Fatal("exits function")
    
    help wanted good first issue checker request 
    opened by quasilyte 13
  • all: announcement plans

    all: announcement plans

    This issues is used to track actions we may want to perform to make it possible (and easy) for gophers to find our project. In other words, this is a tracking issue for our public announce.

    ☑ send PR to awesome-go-linters ☑ send PR to awesome-go/code-analysis ☑ spawn reddit/HN thread ☑ post in https://lobste.rs/ ☑ publish https://habr.com article about go-critic + make English translation

    Any additions/ideas are welcome.

    discussion 
    opened by quasilyte 12
  • granular error handling, skip or fail on parsing error

    granular error handling, skip or fail on parsing error

    Provide finer-grained settings to control what to do when a ruleguard parsing error occurs. When a ruleguard parsing error occurs, the linter can decide whether to skip that ruleguard file or error out.

    Different types of parsing errors may occur: DSL syntax error, imported package. In the future, other types of errors could be introduced.

    This PR depends on https://github.com/quasilyte/go-ruleguard/pull/217. I.e. build will not succeed until that dependent PR is merged. This should help address https://github.com/quasilyte/go-ruleguard/issues/215

    Examples:

    $ gocritic check [email protected]=dsl \
      [email protected] rules/rule1.go,rules/rule3.go,rules/rule2.go \
      -enable ruleguard   main.go
    ruleguard init error, skip rules/rule2.go: rules/rule1.go:1: can't load github.com/CiscoM31/test/worker2
    $ echo $?
    0
    $ gocritic check [email protected]=import \
      [email protected] rules/rule1.go,rules/rule3.go,rules/rule2.go \
      -enable ruleguard   main.go
    init checkers: ruleguard init error: rules/rule1.go:1: can't load github.com/CiscoM31/test/worker2
    $ echo $?
    1
    
    opened by sebastien-rosset 11
  • Build failed by instructions from readme

    Build failed by instructions from readme

    Under Ubuntu 18.04 and CentOS 7 with go1.10.2 linux/amd64 I am unable to buid go-critic: go get -v github.com/go-lintpack/lintpack/... go get -v github.com/go-critic/go-critic/... lintpack build -o gocritic -linter.name='gocritic' github.com/go-critic/go-critic/checkers can't load package: package /tmp/linter*.go172919041: import "/tmp/linter*.go172919041": cannot import absolute path

    bug 
    opened by ElMaxo 10
  • lint/switchif: handle switch statements with multiple

    lint/switchif: handle switch statements with multiple "case" values properly

    github.com/go-critic/go-critic/lint/stddef_checker.go:192:4: switchif: should rewrite switch statement to if statement
    
    switch fn.Name {
    case "uint", "int":
    	c.warn(call, "math/bits.UintSize")
    }
    

    This switch has 1 case, but that case has 2 values. It has the same semantics as:

    switch fn.Name {
    case "uint":
    	c.warn(call, "math/bits.UintSize")
    case "int":
    	c.warn(call, "math/bits.UintSize")
    }
    // Or 
    switch fn.Name {
    case "uint":
    	fallthrough
    case "int":
    	c.warn(call, "math/bits.UintSize")
    }
    

    switchif should not give a warning in this case.

    bug in progress 
    opened by quasilyte 10
  • lint: yodaStyleExpr considers if '0' <= c && c <= '9' as non-idiomatic

    lint: yodaStyleExpr considers if '0' <= c && c <= '9' as non-idiomatic

    The Go team highly mandates to express a value range check as

     if '0' <= c && c <= '9' { 
    	// character range ok
    }
    

    instead of

     if c >= '0'  && c <= '9' { 
    	// character range ok
    }
    

    so the yodaStyleExpr should respect this and cease to warn about that.

    NOTE: This like an regression that might have been introduced by PR #856 while trying to fix issue #355 before.

    good first issue 
    opened by nightlyone 9
  • lint: unnamedResult should not warn on different named types

    lint: unnamedResult should not warn on different named types

    Reproducer:

    gocritic check-package -enable=unnamedResult io
    

    Output:

    io/pipe.go:186:1: unnamedResult: consider to give name to results
    

    Code:

    func Pipe() (*PipeReader, *PipeWriter) {
    

    In my opinion, this signature is perfectly fine. If there are distinct named types, type names serve as a "concise names".

    Negative test suite should be extended as well.

    bug 
    opened by quasilyte 9
  • build(deps): bump github.com/quasilyte/go-ruleguard/dsl from 0.3.21 to 0.3.22

    build(deps): bump github.com/quasilyte/go-ruleguard/dsl from 0.3.21 to 0.3.22

    Bumps github.com/quasilyte/go-ruleguard/dsl from 0.3.21 to 0.3.22.

    Commits
    • 5158b61 dsl: add Object.IsVariadicParam
    • cb003bc readme: fix typos (#426)
    • ce1bf37 rules: add sort.Float64s to sortFuncs (#418)
    • 071b71c docs: update links and fix a few typos (#419)
    • 1204f12 analyzer: use sync.Pool to re-use ruleguard runner state (#416)
    • 9af9b08 ruleguard: introduce reusable runner state (#415)
    • 824e91a build(deps): bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#405)
    • ae42498 ruleguard/typematch: replace Split with Index to avoid allocs (#414)
    • 92ca799 ruleguard: remove matchData allocations (#413)
    • 0588088 Add troubleshooting sectipon to README.md (#411)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies go 
    opened by dependabot[bot] 0
  • build(deps): bump golang.org/x/tools from 0.3.0 to 0.4.0

    build(deps): bump golang.org/x/tools from 0.3.0 to 0.4.0

    Bumps golang.org/x/tools from 0.3.0 to 0.4.0.

    Release notes

    Sourced from golang.org/x/tools's releases.

    gopls/v0.4.0

    • Improved support for working with modules (@​ridersofrohan). A detailed walk-through of the new features can be found here. A quick summary:
      • Use the -modfile flag to suggest which modules should be added/removed from the go.mod file, rather than editing it automatically.
      • Suggest dependency upgrades in-editor and provide additional language features, such as formatting, for the go.mod file.
    • Inverse implementations (@​muirdm). "Go to implementations" on a concrete type will show the interfaces it implements.
    • Completion improvements (@​muirdm). Specifically, improved completion for keywords. Also, offer if err != nil { return err } as a completion item.
    • Jumping to definition on an import statement returns all files as definition locations (@​danishprakash).
    • Support for running go generate through the editor, via a code lens (@​marwan-at-work).
    • Command-line support for workspace symbols (@​daisuzu).

    Opt-in:

    • Code actions suggesting gofmt -s-style simplifications (@​ridersofrohan). To get these on-save, add the following setting:
    "[go]": {
    	"editor.codeActionsOnSave": {
    		"source.fixAll": true,
    	}
    }
    
    • Code actions suggesting fixes for type errors, such as missing return values (goreturns-style), undeclared names, unused parameters, and assignment statements that should be converted from := to = (@​ridersofrohan). Add the following to your gopls settings to opt-in to these analyzers. In the future, they will be on by default and high-confidence suggested fixes may be applied on save. See additional documentation on analyzers here.
    "gopls": {
    	"analyses": {
    		"fillreturns": true,
                    "undeclaredname": true,
                    "unusedparams": true,
                    "nonewvars": true,
    	}
    }
    
    • Further improvements in the support for multiple concurrent clients (@​findleyr). See #34111 for all details.

    For a complete list of the issues resolved, see the gopls/v0.4.0 milestone.

    gopls/v0.3.4

    gopls/v0.3.3

    • Support for workspace symbols. (@​daisuzu)
    • Various completion improvements, including fixes for completion in code that doesn't parse. (@​muirdm)
    • Limit diagnostic concurrency, preventing huge spikes in memory usage that some users encountered. (@​heschik)
    • Improved handling for URIs containing escaped characters. (@​heschik)
    • Module versions from "go list" in pkg.go.dev links. (@​ridersofrohan)

    ... (truncated)

    Commits
    • aee3994 gopls/internal/lsp/fake: in (*Workdir).RenameFile, fall back to read + write
    • fe60148 go.mod: update golang.org/x dependencies
    • c9ea9a7 gopls/internal/regtest: add a test for the case when the renaming package's p...
    • bf5db81 gopls/internal/lsp/cache: improve ad-hoc warning for nested modules
    • aa9f4b2 go/analysis: document that facts are gob encoded in one gulp
    • bdcd082 internal/gcimporter: skip tests earlier when 'go build' is not available
    • 2ad6325 gopls/internal/lsp/cache: expand ImportPath!=PackagePath comment
    • 52c7b88 gopls/internal/robustio: only define ERROR_SHARING_VIOLATION on Windows
    • 4f69bf3 gopls/internal/lsp/cache: narrow reloadOrphanedFiles to open files
    • 6002d6e gopls/internal/regtest/misc: test Implementations + vendor
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies go 
    opened by dependabot[bot] 0
  • build(deps): bump github.com/cristalhq/acmd from 0.8.1 to 0.11.0

    build(deps): bump github.com/cristalhq/acmd from 0.8.1 to 0.11.0

    Bumps github.com/cristalhq/acmd from 0.8.1 to 0.11.0.

    Release notes

    Sourced from github.com/cristalhq/acmd's releases.

    v0.11.0

    ed4f464af0957e53760f17068e03ad074d1647f5 Refactor help (#46) a1e96d9f557d6a664d537dcda86a2e7f7a1737e9 Update example test & readme (#45) 46744d4b5e5ffa13e79f6b395a8a831721fc0c82 Show subcommands in help (#44)

    v0.10.0 - BREAKING CHANGE

    No more Do field, use Exec or ExecFunc

    v0.9.2

    fb34dae6dbb1df230fd67115d11bc6677f983459 Add weekly builds (#41) 56a101694c72dd524414eac072740f3e112afa64 Drop Do (#36)

    v0.9.1

    1b0fa23f87e502a3d04baedb83dcf7d7af7498a7 Rename FlagSetter to FlagsGetter (#40)

    v0.9.0

    bf7d1f2f9bab9f0eb7ed44afa3b1217b1df958b6 Add flags support (#39)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies go 
    opened by dependabot[bot] 0
  • checkers(wrapperFunc): suggest `strings.Cut` instead of `strings.Index`

    checkers(wrapperFunc): suggest `strings.Cut` instead of `strings.Index`

    This change utilize strings.Cut, a new function added in go 1.18, which turned out quite useful.

    Unfortunately, the current implementation does not cover all cases, e.g. the same examples won't match if the := operator is used instead of =. I wonder if we should just copy-paste the same checks with different operators 🤔

    Also, a similar function exists in the bytes package, so we could implement the bytes.Index -> bytes.Cut check as well (in another PR, I guess).

    opened by junk1tm 0
  • caseOrder: type is not defined if type is defined in another file in the same package

    caseOrder: type is not defined if type is defined in another file in the same package

    I put my struct type definition into separate file named shema.go and added this typeswitch statement:

    switch value := payload.(type) {
    case CustomerLead: // <-- this is my struct type
        // do something
    default:
        log.Printf("Don't know what to do with %v", value)
    }
    

    And if I run gocritic as gocritic check file-with-switch.go as a result I got an error

    caseOrder: type is not defined CustomerLead
    

    I don't wanna put all my code in one file 😸 Have any ideas how it can be fixed?

    opened by Ivan-Feofanov 3
Releases(v0.6.5)
  • v0.6.5(Aug 28, 2022)

    • checkers: return an error instead of panic in InitEmbeddedRules (https://github.com/go-critic/go-critic/pull/1250)
    • docs: update README install instruction for go 1.18 (https://github.com/go-critic/go-critic/pull/1254)
    • checkers: fix reflect.Value suggestion in redundantSprint (https://github.com/go-critic/go-critic/pull/1260)
    • update astequal and astcopy packages (https://github.com/go-critic/go-critic/pull/1261)
    • checkers: fix typeUnparen for func type literals (https://github.com/go-critic/go-critic/pull/1262)
    • checkers: fix httpNoBody suggestion (https://github.com/go-critic/go-critic/pull/1204)
    • update ruleguard to 0.3.18 (https://github.com/go-critic/go-critic/pull/1263)
    Source code(tar.gz)
    Source code(zip)
  • v0.6.4(Aug 11, 2022)

    • Updated ruleguard and x/tools
    • all: use cristalhq/acmd #1198
    • checkers: add time range expr simplify (https://github.com/go-critic/go-critic/pull/1220)
    • ci: add Go 1.18 (https://github.com/go-critic/go-critic/pull/1240)
    • checkers: turn init() for embedded rules into exported func (https://github.com/go-critic/go-critic/pull/1246)
    • checkers: don't call SizeOf for type parameters (https://github.com/go-critic/go-critic/pull/1237)
    • checkers: supported generics for typeDefFirst and paramTypeCombine (https://github.com/go-critic/go-critic/pull/1239)
    • checkers: use ctx.SizeOf instead of SizesInfo.SizeOf (https://github.com/go-critic/go-critic/pull/1247)

    A special thanks goes to @mcdoker18, @cristaloleg and @peakle + everyone who helps to keep this project afloat.

    Source code(tar.gz)
    Source code(zip)
  • v0.6.3(Apr 9, 2022)

    Checkers

    • checkers: add todoCommentWithoutDetail #1169
    • checkers: add new checker stringsCompare #1195

    Features

    • ruleguard: add filter by tags for analyzer mode #1205
    • checkers: add skip experimental tag by default for user defined rules #1217

    Deps

    • deps: remove colored output support (https://github.com/go-critic/go-critic/pull/1207)\
    • update ruleguard #1214
    Source code(tar.gz)
    Source code(zip)
    gocritic-darwin-amd64(9.45 MB)
    gocritic-darwin-arm64(10.47 MB)
    gocritic-linux-amd64(9.59 MB)
    gocritic-linux-arm64(9.34 MB)
    gocritic-windows-amd64.exe(9.78 MB)
    gocritic-windows-arm64.exe(9.42 MB)
  • v0.6.2(Jan 10, 2022)

    Checkers

    • checkers: add deferInLoop checker (#1145)
    • checkers: add dynamicFmtString checker (#1156)

    Fixes

    • checkers: update preferWriteByte (#1151)
    • checkers: treat //noinspection as pragma in commentFormatting (#1166)
    • checkers: fix equalFold rules autofix templates (#1178)
    • checkers: ignore labeled continue in select statement (#1158)

    Improvements

    • checkers: add At() for httpNoBody checker (#1164)
    • checkers: add enable/disable flags to ruleguard checker (#1181)
    • checker/whyNoLint: compile regex when it is needed (#1182)
    • checkers: add fixable for commentFormatting (#1190) (#1191)

    Tests

    • checkers: add more octalLiteral tests (#1150)
    • checkers: add tests for #1166 (#1172)
    • checkers: add few lines test cases for deprecatedComment (#1189)

    Docs

    • checkers/preferFprint: fix docs (#1142)

    Development

    • checkers: add hidden ruleguard debug handle (#1134)
    • tools: move tools into own module (#1162)
    • checkers: move out embedded rules from checkers.go (#1186)

    Performance

    • checkers: optimize deprecatedComment (#1188)
    • checkers: optimize commentFormatting (#1192)
    Source code(tar.gz)
    Source code(zip)
    gocritic-darwin-amd64(9.42 MB)
    gocritic-darwin-arm64(10.45 MB)
    gocritic-linux-amd64(9.56 MB)
    gocritic-linux-arm64(9.28 MB)
    gocritic-windows-amd64.exe(9.75 MB)
    gocritic-windows-arm64.exe(9.40 MB)
  • v0.6.1(Oct 20, 2021)

  • v0.6.0(Oct 18, 2021)

    Special notes

    • We're hitting the 100 checkers threshold! :tada:
    • Several old checkers are rewritten in ruleguard rules! :tada:
    • Our project passed 1000 stars at last! :tada:

    This release is very special. :heart:

    New checkers

    • added emptyDecl checker (#1120)
    • added externalErrorReassign checker (#1117)
    • added badSorting checker (#1114)
    • added exposedSyncMutex checker (#1111)
    • added timeExprSimplify checker (#1112)
    • added syncMapLoadAndDelete checker (#1092)
    • added sprintfQuotedString checker (#1092)

    Checker improvements and fixes

    • dupCase now checks select statements (#1116)
    • more offby1 checker patterns (#1094)
    • made sloppyTypeAssert more conservative (#1113)
    • made yodaStyleExpr more conservative (#1105)
    • ignore else { if <init> {...} } in elseif checker (#1102)
    • octalLiteral checker is reworked completely (#1101)
    • unnecessaryBlock now reports redundant {} in case/comm clauses (#1097)

    Misc

    • allow target Go version constraint (#1074)
    • ruleguard version is updated to v0.3.11
    • docs: render total checkers count in the output (#1115)

    Contributors: @quasilyte @cristaloleg @tamaravedenina

    Source code(tar.gz)
    Source code(zip)
    gocritic-darwin-amd64.zip(4.67 MB)
    gocritic-darwin-arm64.zip(4.47 MB)
    gocritic-linux-amd64.zip(5.53 MB)
    gocritic-linux-arm64.zip(4.37 MB)
    gocritic-windows-amd64.zip(4.85 MB)
    gocritic-windows-arm64.zip(4.45 MB)
  • v0.5.8(Oct 11, 2021)

    Fixes

    • checkers/octalLiteral: skip check for fs package (#1062)
    • checkers/commentFormatting: should allow vertical bars (#1066)
    • fixes dsl package dependency

    Checkers

    • checkers: add preferFprint rule (#1070)
    • checkers: add returnAfterHttpError (#1079)
    • checkers: add redundantSprint checker (#1086)
    • checkers: add preferFilepathJoin (#1078)
    • checkers: add preferStringWriter (#1077)
    • checkers: add sliceClear rule (#1087)
    • checkers: add preferWriteByte (#1067)
    • httpNoBody: add NewRequestWithContext (#1076)
    • checkers: add more dupArg patterns (#1089)
    • Ported several checkers to the ruleguard rules

    Misc

    • granular error handling, skip or fail on parsing error (#1024)
    • udpate ruleguard to 0.3.9 (#1084)
    • all: add initial quickfix support (#1088)

    Special thanks to @peakle, @sebastien-rosset, @tdakkota and @cristaloleg

    Source code(tar.gz)
    Source code(zip)
    gocritic-darwin-amd64.zip(4.91 MB)
    gocritic-darwin-arm64.zip(4.79 MB)
    gocritic-linux-amd64.zip(5.42 MB)
    gocritic-linux-arm64.zip(4.76 MB)
    gocritic-windows-amd64.zip(5.08 MB)
  • v0.5.7(Jun 6, 2021)

    Fixes

    • checkers: fix typeUnparen suggestions for chan types

    Checkers

    • checkers: add preferDecodeRune (#1043)
    • checkers: add ioutilDeprecated (#1054)

    Changes

    • checkers: make it possible to write embedded ruleguard rules

    Docs

    • ci: auto update docs (#1047)
    • checkers: fixed deferUnlambda "after" docs (#1048)

    Chore

    • checkers: rewrite several checkers using the ruleguard rules (#1046)
    • checkers: rewrite badLock with ruleguard patterns (#1052)
    • checkers: rewrite deferUnlambda in terms of ruleguard rules (#1058)
    Source code(tar.gz)
    Source code(zip)
  • v0.5.6(Apr 22, 2021)

    Changes

    • update github.com/quasilyte/go-ruleguard to v0.3.4 @pierrre (#1041)
    • upgrade ruleguard to 0.3.2 @sebastien-rosset (#1032)

    Checkers

    • appendAssign: also warn on short decl @adlerjohn (#1034)

    Docs

    • checkers: update sloppyTypeAssert_checker docs @cristaloleg (#1039)
    • readme: add MacPorts install info @herbygillot (#1038)

    Chore

    • framework: fix some linting issues @quasilyte (#1042)
    Source code(tar.gz)
    Source code(zip)
  • v0.5.5(Mar 15, 2021)

    New checkers

    • checker: tooManyResults @cristaloleg (#974)

    Bug fixes

    • checkers: commentFormatting: allow - in pragma tag names @quasilyte (#1031)
    • checkers: fix emptyFallthrough false positive on default @quasilyte (#1030)

    Checker improvements

    • extend nilValReturn checker @tamaravedenina (#1025)

    Other

    • add rulestest to test our rules.go file @quasilyte (#1029)
    • checkers: update ruleguard @quasilyte (#1023)
    • update contributing file @tamaravedenina (#1026)
    Source code(tar.gz)
    Source code(zip)
  • v0.5.4(Jan 31, 2021)

    Changes

    • checkers: constructors now can return error @sebastien-rosset (#1020)
    • checkers: update ruleguard to v0.3.0 @quasilyte (#1018)
    • Add support for glob pattern in ruleguard/rules configuration @sebastien-rosset (#1011)
    Source code(tar.gz)
    Source code(zip)
  • v0.5.3(Dec 29, 2020)

    Improvements

    • extend flagName diagnostics @quasilyte (#1005)
    • enable ruleguard debug via [email protected]=<name> @quasilyte (#1002)
    • ruleguard now supports multi rules input @quasilyte (#1001)
    • improve exitAfterDefer warnings text @josephzidell (#978)

    New checkers

    • added badLock checker @quasilyte (#999)
    • added builtinShadowDecl @quasilyte (#970)
    • added typeDefFirst checker @LevOspennikov (#960)

    Fixes

    • fix stringXbytes @cristaloleg (#1013)
    • fix unlambda false positive on ptr vars @quasilyte (#1008)
    • fix unlambda panic on variadic func literals @quasilyte (#992)
    • ignore defer exit() in exitAfterDefer @quasilyte (#996)
    • don't warn on nolint with reason in commentFormatting @quasilyte (#986)
    • make argOrder checker more conservative @quasilyte (#969)
    Source code(tar.gz)
    Source code(zip)
    gocritic-darwin-amd64.zip(4.53 MB)
    gocritic-linux-amd64.zip(5.08 MB)
    gocritic-linux-arm64.zip(4.42 MB)
    gocritic-windows-amd64.zip(4.70 MB)
  • v0.5.2(Aug 14, 2020)

    Changes

    • checkers: mark more checkers as stable @quasilyte (#956)

    Checkers that are now considered to be stable:

    * argOrder
    * badCall
    * badCond
    * codegenComment
    * commentFormatting
    * deprecatedComment
    * exitAfterDefer
    * flagName
    * mapKey
    * newDeref
    * offBy1
    * stringXbytes
    * valSwap
    * wrapperFunc
    

    Every checker from this list was tested on several big Go projects.

    Source code(tar.gz)
    Source code(zip)
  • v0.5.1(Aug 12, 2020)

    Updated go-ruleguard version to v0.2.0.

    This minor release is an attempt to fix a broken dependency. See https://github.com/go-critic/go-critic/issues/953

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Jun 15, 2020)

    It's now possible to install go-critic with go get (no lintpack required).

    New checkers:

    • 9a11c853c16165ba631c16690a5cc33e00ba4318 added deferUnlambda checker.
    • 99489e11b861ed8d22dc71350aa171a83847a3eb added badRegexp checker.
    • 3a3e88517f5d7d6095dce667cb4ed7be70c16741 added regexpSimplify checker.
    • 39162297c14d259ef3664dda6a9d4ff827ef56b0 added sloppyTypeAssert checker.
    • d6fa699cebedde3b84aa546281fee12e7ce4218e added sqlQuery checker.
    • 33d100bf5d7c13bcfbc2ff980df8f6493188a202 added sortSlice checker.

    Fixes:

    • 4757c17fa00cc193bd382ac15455654ca36078ee typeSwitchVar now generates 1 warning per switch statement.
    • 7668b863d36606b194de6d1867b25674e53081b8 commentFormatting does not report //go:generate comments.
    • 730db5a54f7247ee9953f1795738e785073051be commentFormatting does not report //export comments.
    • f4eb84b5d19c8a313a19be080059328c71a88144 unnecessaryDefer false positive fix.
    Source code(tar.gz)
    Source code(zip)
    gocritic-0.5.0-darwin-amd64.zip(4.42 MB)
    gocritic-0.5.0-linux-amd64.zip(4.95 MB)
    gocritic-0.5.0-windows-amd64.zip(4.58 MB)
  • untagged-efed75e258f9c63dc64c(Mar 18, 2020)

    Changes

    • checkers: add ruleguard checker @quasilyte (#907)
    • add draw.Draw to draw.DrawMask checker @seregayoga (#904)
    • checkers: rename deferAtTheEnd to unnecessaryDefer @quasilyte (#902)
    • checker: add defer at the end of function checker @janisz (#901)
    Source code(tar.gz)
    Source code(zip)
  • v0.4.1(Jan 7, 2020)

    Changes

    • all: rename release-config.yaml to release-drafter.yml @cristaloleg (#898)
    • readme: add "cd" step to installation guide @quasilyte (#896)
    • checkers: add mapKey checker @quasilyte (#895)
    • checkers: fix integration tests @quasilyte (#894)
    • all: use Github Actions @cristaloleg (#891)
    • all: make automate releases @cristaloleg (#892)
    • makefile: correct linter.version argument @sosiska (#890)
    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Nov 27, 2019)

  • v0.3.4(Jan 4, 2019)

    • Fixed a number of false positives and panics for stable checkers
    • Moved to a lintpack framework which uses https://godoc.org/golang.org/x/tools/go/packages
    • Improved the test suite for checkers
    • Moved less maintained and too experimental checkers to contrib repo

    Marked several checkers stable. The current list of stable checkers:

    appendAssign [diagnostic]
    appendCombine [performance]
    assignOp [style]
    builtinShadow [style opinionated]
    captLocal [style]
    caseOrder [diagnostic]
    defaultCaseOrder [style]
    dupArg [diagnostic]
    dupBranchBody [diagnostic]
    dupCase [diagnostic]
    dupSubExpr [diagnostic]
    elseif [style]
    flagDeref [diagnostic]
    hugeParam [performance]
    ifElseChain [style]
    importShadow [style opinionated]
    indexAlloc [performance]
    paramTypeCombine [style opinionated]
    rangeExprCopy [performance]
    rangeValCopy [performance]
    regexpMust [style]
    singleCaseSwitch [style]
    sloppyLen [style]
    switchTrue [style]
    typeSwitchVar [style]
    typeUnparen [style opinionated]
    underef [style]
    unlambda [style]
    unslice [style]
    
    Source code(tar.gz)
    Source code(zip)
Owner
The most opinionated Go source code linter
null
a simple golang SSA viewer tool use for code analysis or make a linter

ssaviewer A simple golang SSA viewer tool use for code analysis or make a linter ssa.html generate code modify from src/cmd/compile/internal/ssa/html.

null 7 May 17, 2022
Staticcheck - The advanced Go linter

The advanced Go linter Staticcheck is a state of the art linter for the Go programming language. Using static analysis, it finds bugs and performance

Dominik Honnef 5.1k Jan 1, 2023
A Go linter to check that errors from external packages are wrapped

Wrapcheck A simple Go linter to check that errors from external packages are wrapped during return to help identify the error source during debugging.

Tom Arrell 204 Dec 27, 2022
A linter that handles struct tags.

Tagliatelle A linter that handles struct tags. Supported string casing: camel pascal kebab snake goCamel Respects Go's common initialisms (e.g. HttpRe

Ludovic Fernandez 20 Dec 15, 2022
The Golang linter that checks that there is no simultaneous return of `nil` error and an invalid value.

nilnil Checks that there is no simultaneous return of nil error and an invalid value. Installation & usage $ go install github.com/Antonboom/nilnil@la

Anton Telyshev 13 Dec 14, 2022
Go linter which checks for dangerous unicode character sequences

bidichk - checks for dangerous unicode character sequences bidichk finds dangerous unicode character sequences in Go source files. Considered dangerou

Lucas Bremgartner 27 Oct 5, 2022
Go linter that checks types that are json encoded - reports unsupported types and unnecessary error checks

Checks types passed to the json encoding functions. Reports unsupported types and reports occations, where the check for the returned error can be omited.

Lucas Bremgartner 28 Oct 7, 2022
Linter for PostgreSQL

Использование Проверить миграции: oh-my-pg-linter check ./migrations/*.sql Добавить директории с дополнительными проверками (переопределение - кто пос

Denis Kayumov 0 Nov 25, 2021
containedctx detects is a linter that detects struct contained context.Context field

containedctx containedctx detects is a linter that detects struct contained context.Context field Instruction go install github.com/sivchari/contained

sivchari 12 Oct 22, 2022
World's spookiest linter

nosleep The world's spookiest linter nosleep is a golang-ci compatible linter which checks for and fails if it detects usages of time.Sleep. Why did y

Elliot Williams 1 Oct 15, 2022
Go linter to analyze expression groups: require 'import' declaration groups

grouper — a Go linter to analyze expression groups Installation

null 0 Jun 19, 2022
funcresult — a Go linter to analyze function result parameters

Go linter to analyze function result parameters: require named / unnamed function result parameters

null 0 Jan 27, 2022
nostdglobals is a simple Go linter that checks for usages of global variables defined in the go standard library

nostdglobals is a simple Go linter that checks for usages of global variables defined in the go standard library

Nassos Kat 1 Feb 17, 2022
Goalinter-v1: Goa framework (version1) linter

goavl: Goa framework (ver1) linter goavlは、goa version1(フォーク版)のlinterです。開発目的は、goa

CHIKAMATSU Naohiro 1 Jul 28, 2022
Linter for Go's fmt.Errorf message

wrapmsg wrapmsg is Go code linter. this enforces fmt.Errorf's message when you wrap error. Example // OK ???? if err := pkg.Cause(); err != nil { re

Shinnosuke Sawada 12 Dec 27, 2022
misspelled word linter for Go comments, string literals and embedded files

gospel The gospel program lints Go source files for misspellings in comments, strings and embedded files. It uses hunspell to identify misspellings an

Dan Kortschak 30 Aug 6, 2022
octocov is a tool for collecting code metrics (code coverage, code to test ratio and test execution time).

octocov is a tool for collecting code metrics (code coverage, code to test ratio and test execution time).

Ken’ichiro Oyama 159 Jan 9, 2023
depth is tool to retrieve and visualize Go source code dependency trees.

depth is tool to retrieve and visualize Go source code dependency trees. Install Download the appropriate binary for your platform from the Rele

Kyle Banks 810 Dec 30, 2022
Print all source code for a given go package or module.

gosrcs gosrcs is a tool to print all the source code a given go package depends on. The original motivation of this tool is to integrate go builds int

null 3 Oct 25, 2021