This page describes checks supported by go-critic linter.
checker is enabled by default.
checker is disabled by default.
Diagnostics try to find programming errors in the code. They also detect code that may be correct, but looks suspicious.
All diagnostics are enabled by default (unless it has “experimental” tag).
Style checks suggest replacing some form of expression/statement with another one that is considered more idiomatic or simple.
Only non-opinionated style checks are enabled by default.
Performance checks tell you about potential issues that can make your code run slower than it could be.
All performance checks are disabled by default.
Detects suspicious append result assignments.
Detects append chains to the same slice that can be done in a single append call.
Detects assignments that can be simplified by using assignment operators.
Detects bool expressions that can be simplified.
Detects when predeclared identifiers shadowed in assignments.
Detects capitalized names for local variables.
Detects erroneous case order inside switch statements.
Detects malformed ‘code generated’ file comments.
// Code generated by foogen. DO NOT EDIT.
Detects comments with non-idiomatic formatting.
Detects commented-out code inside function bodies.
Detects when default case in switch isn’t on 1st or last position.
Detects comments that silence go lint complaints about doc-comment.
// Foo is a demonstration-only function.
Detects duplicated branch bodies inside conditional statements.
Detects duplicated case clauses inside switch statements.
Detects else with nested if statement that can be replaced with else-if.
Detects fallthrough that can be avoided by using multi case values.
Detects empty string checks that can be written more idiomatically.
Detects unoptimal strings/bytes case-insensitive comparison.
Detects calls to exit/fatal inside functions that use defer.
Detects immediate dereferencing of flag package pointers.
Suggests to use pointer to array to avoid the copy using & on range expression.
Dereferencing returned pointers will lead to hard to find errors where flag values are not updated after flag.Parse().
Detects flag names with whitespace.
Detects hex literals that have mixed case letter digits.
Detects params that incur excessive amount of copying.
Detects repeated if-else statements and suggests to replace them with switch statement.
Permits single else or else-if; repeated else-if or else + else-if will trigger suggestion to use switch statement. See EffectiveGo#switch.
Detects when imported package names shadowed in the assignments.
Detects strings.Index calls that may cause unwanted allocs.
Detects non-assignment statements inside if/switch init clause.
Detects method expression call that can be replaced with a method call.
Finds where nesting level could be reduced.
Detects return statements those results evaluate to nil.
// (B) - typo in "==", change to "!="
Detects octal literals passed to functions.
Detects various off-by-one kind of errors.
Detects if function parameters could be combined by type and suggest the way to do it.
Detects input and output parameters that have a type of pointer to referential type.
Detects expensive copies of for loop range expressions.
See Go issue for details: https://github.com/golang/go/issues/15812.
Detects loops that copy big objects during each iteration.
Suggests to use index access or take address and make use pointer instead.
Detects regexp.Compile* that can be replaced with regexp.MustCompile*.
Detects switch statements that could be better written as if statement.
Detects usage of len when result is obvious or doesn’t make sense.
Detects redundant conversions between string and byte.
Detects switch-over-bool statements that use explicit true tag value.
Detects repeated type assertions and suggests to replace them with type switch statement.
// Code A, uses x.
// Code B, uses x.
// Code C, uses x.
Detects type switches that can benefit from type guard clause with variable.
Detects unneded parenthesis inside type expressions and suggests to remove them.
Detects dereference expressions that can be omitted.
Detects function literals that can be simplified.
Detects unnamed results that may benefit from names.
Detects unnecessary braced statement blocks.
Detects slice expressions that can be simplified to sliced expression itself.
Detects value swapping code that are not using parallel assignment.
Detects conditions that are unsafe due to not being exhaustive.
Detects function calls that can be replaced with convenience wrappers.
Detects Yoda style expressions and suggests to replace them.