Quick-fixes
This reference lists quick-fixes for problems that the Go inspections in Go by GoLand report.
The available actions depend on your code, Go version, and enabled inspections. Names and expressions in italics depend on your code.
For instructions, refer to Apply a quick-fix. For inspection descriptions and default settings, refer to Inspections.
Unused declarations
Quick-fix | What it does | Related inspections |
|---|---|---|
Delete constant 'name' | Deletes an unused constant. | |
Delete function | Deletes an unused function. | |
Delete type 'name' | Deletes an unused type declaration. | |
Delete variable 'name' | Deletes an unused variable. | |
Rename to _ | Replaces an unused name with the blank identifier |
Redundant code
Quick-fix | What it does | Related inspections |
|---|---|---|
Delete blank argument | Removes an unnecessary blank identifier from a | |
Delete conversion | Removes a redundant type conversion. | |
Delete conversion (might change semantics) | Removes a type conversion that can affect the result of the expression. | |
Delete empty declaration | Removes an empty | |
Delete import alias | Removes an import alias that duplicates the package name. | |
Delete redundant index | Removes an unnecessary upper bound, such as | |
Delete redundant type | Removes a type and an address operator from a composite literal where Go can infer them. | |
Delete type | Removes a type that Go can infer from a declaration. In an impossible type switch case, removes the type or the whole case. | |
Redundant 'else' branch | Removes an unnecessary | |
Remove redundant 'comma' | Removes an optional trailing comma. | |
Remove redundant 'semicolon' | Removes an unnecessary semicolon. | |
Remove self assignment | Removes an assignment of a value to itself. | |
Unwrap parentheses | Removes unnecessary parentheses around an expression. |
Expressions and control flow
Quick-fix | What it does | Related inspections |
|---|---|---|
Simplify expression | Simplifies a boolean expression, such as | |
Simplify 'expression' to 'value' | Replaces an expression with its constant boolean value, such as | |
Simplify to 'expression' | Removes a redundant boolean literal, such as | |
Remove 'for' loop | Removes a | |
Remove redundant condition | Removes a loop condition that is always | |
Replace with 'select' | Replaces an empty infinite | |
Create 'default' clause | Adds a | |
Create missing iota clauses | Adds | |
Create intermediate variable | Adds a local copy of a loop variable before a function literal captures it. |
Errors and function calls
Quick-fix | What it does | Related inspections |
|---|---|---|
Handle error | Assigns the returned error to a variable and adds an | |
Ignore explicitly | Assigns an unused return value to the blank identifier | |
Wrap error handling in a closure | Wraps a deferred call or a goroutine call in a function literal and adds an error check inside it. | |
Fix error string format | Changes an error string to start with a lowercase letter and removes punctuation at the end. | Error string should not be capitalized or end with punctuation |
Change 'function' to formatting function | Replaces a print function with its formatting variant, such as | |
Convert integer to string using conversion call | Uses a | |
Convert integer to rune | Converts the integer argument to | |
Add pointer | Changes a parameter or receiver type to a pointer so it does not copy a lock. | |
Prepend '&' | Passes the address of an argument to | |
Replace with correct defer construct | Wraps | |
Replace with 'method' and 'return' | Replaces |
Names and code style
Quick-fix | What it does | Related inspections |
|---|---|---|
Rename to 'name' | Removes the package name prefix from an identifier and updates its references. | |
Drop unit-specific suffix 'suffix' | Removes a unit suffix, such as | |
Extract to own declaration | Moves an exported variable or constant into a separate declaration from unexported names. | |
Add 'prefix' prefix to comment | Adds the declaration name or | |
Add whitespace | Adds a space after the comment marker. | |
Sort imports | Sorts imports according to the Go code style settings. | |
Add comma | Adds a trailing comma before a newline in a literal, parameter list, or type argument list. | Missing trailing comma before a newline in a composite literal |
Build tags and directives
Quick-fix | What it does | Related inspections |
|---|---|---|
Add missing newline | Adds a blank line between a | |
Place build tag before package | Moves a | |
Convert //+build comments to //go:build directive | Converts legacy build comments into a | |
Update //+build comments | Updates legacy build comments to match the | |
Place go:debug before package | Moves a | The 'go:debug' directive must be placed before the package clause |
Remove leading whitespace before Go directive | Removes spaces between |
Structs and slices
Quick-fix | What it does | Related inspections |
|---|---|---|
Add keys and delete zero values | Adds field names to a struct literal and removes fields set to their zero values. | |
Update struct 'name' layout | Reorders fields to reduce padding. It stops if any struct literal sets values without field names. | |
Replace with nil (changes semantics) | Replaces an empty slice literal with | |
Replace with nil slice declaration (changes semantics) | Replaces an empty slice initialization with a |
Related locations
These actions help you inspect a problem. They move the caret without changing your code.
Quick-fix | What it does | Related inspections |
|---|---|---|
Navigate to shadowed declaration | Moves the caret to the declaration hidden by the reported variable. | |
Navigate to field 'name' with the same 'tag' tag | Moves the caret to the other struct field that uses the same tag value. | |
Navigate to the end of the problematic execution path | Shows where a path can exit without calling the cancellation function. | |
Navigate to 'name' function | Moves the caret to the cancellation function variable for the reported path. |