go-critic

Trophies

Contributions are partitioned by the check (diagnostic) names.

By the “contribution”, we mean all of these:

  1. Commit that fixes the problem
  2. Reported issue (if there is no commit yet)
  3. Any other form of advice that was suggested by go-critic

The list is sorted by priority. If commit exist, it should be referenced instead of issue. If issue exist, is should be referenced (as opposed of 3 where we have no explicit issue ticket).

This page exists mostly to determine most useful checks that can trigger on real projects. These checks are a good candidates to be included into “default” go-critic list.

Most projects listed here have high base code quality, so every detected issue counts.

Note that this list is not comprehensive. It’s virtually impossible to keep track of all contributions were made.

Diagnostic

argOrder

  1. {gohugoio/hugo} tpl: Fix strings.HasPrefix args order
  2. {syncthing/syncthing} cmd/syncthing: Correct strings.HasPrefix args order
  3. {etcd-io/etcd} Fix strings.HasPrefix args order
  4. {goreleaser/goreleaser} fix: brew strings.HasPrefix args order
  5. {golang/go} net/rpc: fix args order in strings.Contains call

dupSubExpr

  1. {golang/go} cmd/compile/internal/ssa: fix partsByVarOffset.Less method
  2. {securego/gosec} fix duplicated index issue in Less method

caseOrder

  1. {coreos/etcd} etcdctl/ctlv2/command: fix type switch case order

commentedOutCode

  1. {golang/go} cmd/link/internal/sym: uncomment code for ELF cases in RelocName
  2. {go-kit/kit} metrics: remove commented-out debug code
  3. {Microsoft/DUCK} backend/ducklib: remove commentedOutCode from server.go
  4. {Microsoft/DUCK} backend/ducklib/handlers/documents: remove commented-out debug code
  5. {Microsoft/KubeGPU} crishim/pkg/kubeadvertise: remove commented-out code
  6. {future-architect/vuls} config: remove commented-out code from tomlloader
  7. {golang/dep} cmd/dep,gps: remove commented-out code

appendAssign

  1. {ethereum/go-ethereum} dashboard: append to proper slice

dupBranchBody

  1. {go-gitea/gitea} Remove duplicated if bodies

Style

builtinShadow

  1. {ncw/rclone} all: fix go-critic linter suggestions
  2. {v2ray/v2ray-core} s/len/length/ s/cap/capacity/ to avoid builtin shadowing

defaultCaseOrder

  1. {go-gitea/gitea} Make switch more clear

ifElseChain

  1. {mvdan/sh} syntax: replace if-else chains with expr switch stmt
  2. {afiskon/go-elector} minor style fixes
  3. {google/go-cloud} all: simplify and clarify some expressions
  4. {v2ray/v2ray-core} app/router: rewrite if-else chain to switch
  5. {jinzhu/gorm} rewrite if-else chain as switch statement

paramTypeCombine

  1. {intel-go/nff-go} Modified style in merge function
  2. {afiskon/go-elector} minor style fixes

underef

  1. {golang/go} runtime: remove redundant explicit deref in trace.go
  2. {google/go-github} Remove redundant dereference of time.Time
  3. {ncw/rclone} all: fix go-critic linter suggestions

unslice

  1. {golang/go} runtime: simplify slice expression to sliced value itself
  2. {ncw/rclone} all: fix go-critic linter suggestions
  3. {src-d/gitbase} internal/rule: simplify slice expression to sliced value itself
  4. {Microsoft/opengcs} service/gcsutil/gcstools: simplify slice expression to sliced value itself
  5. {future-architect/vuls} commands: simplify slice expression to sliced value itself
  6. {grafeas/grafeas} Simplify slicing of s to s where s is a slice
  7. {influxdata/influxdb} Simplify slicing of s to s where s is a slice
  8. {sourcegraph/sourcegraph} Simplify slicing of s to s where s is a slice

boolExprSimplify

  1. {golang/go} cmd/internal/obj/arm64: simplify some bool expressions
  2. {coreos/etcd} etcdserver/api/v2discovery: simplify !(x == y) to x != y
  3. {openshift/origin} build/controller/build: simplify bool exprs
  4. {google/go-cloud} all: simplify and clarify some expressions
  5. {beego/beego} all: simplify boolean expressions
  6. {golang/dep} gps: simplify boolean expression

switchTrue

  1. {golang/go} math,net: omit explicit true tag expr in switch
  2. {src-d/gitbase} internal/rule: simplify switch true {...} to switch {...}

typeUnparen

  1. {golang/go} archive/tar: remore redundant parens in type expressions
  2. {upspin/upspin} pack/internal/packtest: remove redundant parens in type conv
  3. {ncw/rclone} all: fix go-critic linter suggestions
  4. {src-d/gitbase} remove redundant parenthesis

unlambda

  1. {golang/go} strings, bytes: avoid unnecessary function literals
  2. {gobufallo/buffalo} internal/release,render: remove redundant func wrapping
  3. {openshift/origin} apps: replace func lits with wrapped func value
  4. {go-kit/kit} metrics/internal/convert: use method value insetad of lambda
  5. {golang/dep} gps: replace redundand lambda wrapper with method value

sloppyLen

  1. {gobufallo/buffalo} buffalo/cmd: make len comparison more clear
  2. {graphql-go/graphql} replace len(x)<=v with len(x)==v
  3. {securego/gosec} replace len(x)<=0 with len(x)==0
  4. {go-gitea/gitea} Remove check for negative length
  5. {go-kit/kit} sd/lb: replace len(x)<=0 with len(x)==0
  6. {golang/dep} cmd/dep: replace len(x)<=0 with len(x)==0

typeSwitchVar

  1. {graphql-go/graphql} use type switch with var binding
  2. {intel-go/nff-go} Modified style in merge function
  3. {ethereum/go-ethereum} all: simplify switches
  4. {google/go-cloud} all: simplify and clarify some expressions
  5. {go-gitea/gitea} Use type switch

regexpMust

  1. {graphql-go/graphql} replace regexp.Compile with regexp.MustCompile

singleCaseSwitch

  1. {graphql-go/graphql} simplify single case type switches
  2. {mvdan/sh} interp,syntax: replace single case switches
  3. {go-reform/reform} parse: replace 1 case switch with if
  4. {minio/minio} simplifying if-else chains to switches
  5. {ethereum/go-ethereum} all: simplify switches
  6. {Microsoft/KubeGPU} utils: replace single case type switch with if

assignOp

  1. {graphql-go/graphql} simplify assignments with op= syntax
  2. {go-kit/kit} metrics/teststat: replace x = x <op> y with x <op>= y
  3. {Microsoft/KubeGPU} plugins: simplify x = x <op> y to x <op>= y
  4. {future-architect/vuls} report: simplify x = x <op> y to x <op>= y
  5. {golang/dep} gps: simplify x = x <op> y to x <op>= y
  6. {lucas-clemente/quic-go} simplify x = x <op> ... to x <op>= ...

Performance

appendCombine

  1. {golang/go} net: combine append calls in reverseaddr

rangeValCopy

  1. {golang/go} cmd/link/internal/ld: avoid Reloc copies in range loops

rangeExprCopy

  1. {mvdan/sh} interp: avoid redundant array copies
  2. {ethereum/go-ethereum} all: avoid copying arrays in loops