Inspections
This reference lists the Go inspections included with Go by GoLand. The tables show their names, IDs, descriptions, and default diagnostic severities in VS Code.
An inspection ID identifies a check.
The checks that run depend on your inspection profile, Go version, and code. Syntax errors, unresolved references, and type errors are also reported by the language server.
Declaration redundancy
Inspection | Description | Default severity |
|---|---|---|
Bool condition
| Reports parts of boolean expressions that are always | Warning |
Empty declaration
| Reports empty declarations that have no effect on the program. | Hint |
Empty slice declared using a literal
| Reports slices initialized with an empty literal instead of | Warning |
Redundant blank argument in range
| Reports blank identifiers that you can omit from | Hint |
Redundant comma
| Reports optional trailing commas in argument lists and composite literals. | Hint |
Redundant import alias
| Reports import aliases that duplicate the imported package name and can be omitted. | Hint |
Redundant second index in slices
| Reports an explicit upper bound in a slice expression when you can omit that bound. | Hint |
Redundant semicolon
| Reports semicolons that you can omit under Go syntax rules. | Hint |
Redundant type conversion
| Reports type conversions that you can omit. | Warning or Hint |
Redundant types in composite literals
| Reports explicit types in nested composite literals when the surrounding literal already supplies the type. | Hint |
Self assignment
| Reports assignments of a value to itself. These assignments have no effect. | Warning |
Type can be omitted
| Reports explicit types in variable and constant declarations when the compiler can infer those types. | Hint |
Unused constant
| Reports constants that are declared but never used. | Hint |
Unused exported function
| Reports exported functions with no usages. | Hint |
Unused exported type
| Reports unused exported types in the | Hint |
Unused function
| Reports unexported functions with no usages. | Hint |
Unused global variable
| Reports global variables that are declared but never used. | Hint |
Unused parameter
| Reports function parameters that the function body does not use. | Hint |
Unused type
| Reports types that are declared but never used. | Hint |
Unused type parameter
| Reports type parameters that are declared but never used. | Hint |
Code style
Inspection | Description | Default severity |
|---|---|---|
Comment has no leading space
| Reports comments without a space after the comment marker when your code style settings require one. | Warning |
Comment of exported element starts with the incorrect name
| Reports documentation comments that do not start with the name of the exported declaration they describe. | Warning |
Convert string literals
| Reports double-quoted string literals that can be converted to raw strings, and raw strings that can be converted to double-quoted strings. | No diagnostic by default |
Error string should not be capitalized or end with punctuation
| Reports error strings that start with a capital letter or end with punctuation. | Warning |
Exported element should have a comment
| Reports exported declarations that have no documentation comment. | No diagnostic by default |
Exported element should have its own declaration
| Reports exported variables and constants that share a comma-separated declaration with other names. | Warning |
Name starts with a package name
| Reports exported names that repeat the package name as a prefix. This check excludes the | Warning |
Receiver has a generic name
| Reports generic receiver names such as | Warning |
Redundant 'else' in 'if'
| Reports redundant | Warning |
Redundant 'true' in for loop condition
| Reports an explicit | Warning |
Struct initialization without field names
| Reports struct literals that specify values without field names. By default, this check applies to types defined in another package. | Warning |
Type parameter is declared in lowercase
| Reports type parameter names that contain lowercase letters. | No diagnostic by default |
Unit-specific suffix for 'time.Duration'
| Reports time unit suffixes in names of | Warning |
Unsorted imports
| Reports imports whose order does not follow the | Warning |
Usage of Snake_Case
| Reports variable, constant, and function names that use snake case instead of the mixed capitals convention used in Go. | Warning |
Probable bugs
Inspection | Description | Default severity |
|---|---|---|
'context.CancelFunc' is not called
| Reports execution paths that omit a call to the cancel function returned by | Warning |
'FailNow' in a non-test goroutine
| Reports calls to | Warning |
'Unmarshal' is called with the incorrect argument
| Reports | Warning |
Defer/go statement calls 'recover' or 'panic' directly
| Reports | Warning |
Direct comparison of errors
| Reports direct comparisons between error values that can fail for wrapped errors. The | Warning |
Division by zero
| Reports division by zero. | Warning |
Exceeded shift expression
| Reports shift counts that equal or exceed the bit width of the integer operand. | Warning |
Imported package name as a name identifier
| Reports variable, parameter, and function declarations whose names hide an imported package name. | Warning |
Impossible interface type assertion
| Reports interface type assertions that cannot succeed because the interfaces have methods with the same name but different signatures. | Warning |
Incorrect 'strings.Replace' count argument
| Reports | Warning |
Incorrect usage of 'fmt.Printf' and 'fmt.Println' functions
| Reports incorrect arguments and format strings in | Warning |
Incorrect usage of the 'errors.As' function
| Reports | Warning |
Incorrect usage of the 'sync/atomic' package
| Reports assignments such as | Warning |
Integer to string type conversion
| Reports conversions from an integer to a string, except for | Warning |
Invalid conversions of 'uintptr' to 'unsafe.Pointer'
| Reports unsafe conversions from | Warning |
Irregular usage of 'iota'
| Reports repeated | Warning |
Leading whitespace in directive comment
| Reports whitespace between | Warning |
Locks mistakenly passed by value
| Reports copies of values that contain locks, such as | Warning |
Loop variables captured by the func literal
| Reports references to loop variables in function literals used by | Warning |
Malformed build tag
| Reports build tags with invalid syntax or placement. The Go tool can ignore malformed tags or select the wrong files. | Warning or Information |
Malformed struct tag
| Reports malformed struct tags and tags on unexported fields. | Warning |
Missing 'case' statements for 'iota' consts in 'switch'
| Reports | Warning |
Mixed value and pointer receivers
| Reports types whose methods use a mixture of value receivers and pointer receivers. | Warning |
Nilness analyzer
| Reports problems caused by values that can be | Disabled by default |
Non-standard signature for well-known function names
| Reports methods whose names match standard library interface methods but whose signatures differ. A mismatched signature can prevent the type from satisfying the interface. | Warning |
Reserved word used as name
| Reports declarations whose names hide a built-in identifier, such as | Warning |
Shadowing variable
| Reports variable declarations that hide a variable with the same name in an outer scope. | Hint |
The 'go:debug' directive is ignored in Go versions earlier than 1.21
| Reports | Warning |
The 'go:debug' directive must be placed before the package clause
| Reports | Warning |
Type assertion on errors fails on wrapped errors
| Reports type assertions and type switches on errors that can fail for wrapped errors. The | Warning |
Unhandled error
| Reports calls to functions or methods whose returned | Warning |
Unused function or method call result
| Reports ignored results from functions and methods whose purpose is to return a useful value. | Warning |
Control flow
Inspection | Description | Default severity |
|---|---|---|
'defer' in the loop
| Reports | Warning |
Assignment to a receiver
| Reports assignments to the receiver variable inside a method. The assignment affects only the receiver variable inside that method. | Warning |
Infinite 'for' loop
| Reports empty infinite | Warning |
Unreachable code
| Reports code that no execution path can reach. | Warning |
Data flow analysis
Data flow analysis follows values through your code to find constant conditions, possible nil dereferences, unchecked errors, and resource leaks.
The interprocedural check also follows values across function calls.
Inspection | Description | Default severity |
|---|---|---|
Constant condition
| Reports conditions that always evaluate to | Warning |
Error may be not nil
| Reports uses of results that can be | Warning |
Interprocedural potential nil dereference
| Reports potential | Warning |
Potential nil dereference
| Reports dereferences of pointers that can be | Warning or Information |
Potential resource leak
| Reports resources that can remain unclosed, such as files, SQL rows, HTTP response bodies, and other values that implement | Warning |
General
Inspection | Description | Default severity |
|---|---|---|
Cyclic imports
| Reports cycles in package imports, where a chain of imports leads back to the same package. | Warning |
Deprecated element
| Reports uses of deprecated declarations. | Warning |
Detect usages of runtime.SetFinalizer
| Reports calls to | Warning |
Fuzzing is supported starting with Go 1.18
| Reports fuzz tests when the selected Go SDK is earlier than Go 1.18. | Warning |
Malformed test function name
| Reports test, benchmark, and example function names that do not follow the naming rules of the | Warning |
Missing trailing comma before a newline in a composite literal
| Reports missing trailing commas before a newline in composite literals, function call arguments, and function parameter lists. | Warning |
Redundant parentheses
| Reports unnecessary parentheses in expressions and types. | Warning |
Struct field alignment
| Reports structs whose memory usage can be reduced by reordering fields to decrease padding between them. | Disabled by default |
Unexported return type of the exported function
| Reports exported functions with unexported return types. These types can make the public API harder to use and document. | Warning |
Unnecessarily exported identifier
| Reports exported identifiers that are used only within the package that defines them. | Disabled by default |
Usage of 'interface{}' as a type
| Reports empty interfaces used as types or type constraints when Go 1.18 or later is available. The | No diagnostic by default |
Usage of context.TODO()
| Reports uses of | Disabled by default |