GoLand 2024.3 Help

Disabling and enabling inspections

Some inspections may report problems that you currently do not want to see. In this case, you can disable or suppress them.

Disable inspections

When you disable an inspection, you turn it off. It means that the code analysis engine stops searching project files for the problem that this inspection is designed to detect. Note that when you disable an inspection, you disable it in the current inspection profile; it remains enabled in other profiles.

Most inspections in GoLand can be disabled. However, some inspections will keep highlighting your code regardless of the settings. For example, syntax errors are always highlighted.

Disable an inspection in settings

  1. Press Ctrl+Alt+S to open settings and then select Editor | Inspections.

  2. Locate the inspection you want to disable, and clear the checkbox next to it.

  3. Apply the changes and close the dialog.

You can quickly disable a triggered inspection directly in the editor.

Disable an inspection from the editor

  1. Place the caret at the highlighted line and press Alt+Enter (or click the Intention action icon to use the intention action).

  2. Click the arrow next to the inspection you want to disable, and select Disable inspection.

Disable an inspection from the Problems tool window

  1. In the Inspection Results tab of the Problems tool window (appears once you run code analysis), right-click the inspection you want to disable and select Disable inspection.

  2. Click the Filter resolved items icon to hide the disabled inspection alerts.

Suppress inspections

When you suppress an inspection, the code analysis engine doesn't highlight the problem found by this inspection in the specific piece of code (type, function, or line) . You can also suppress all inspections in the current type.

Most inspections in GoLand can be suppressed. However, some inspections do not have this option. For example, syntax errors are always highlighted in the editor regardless of the settings.

Suppress an inspection from the editor

  1. Place the caret at the highlighted line and press Alt+Enter (or click the Intention action icon to use the intention action).

  2. Click the button next to the inspection you want to suppress and select the suppress action according to the required scope. GoLand adds a // noinspection comment above the code fragment where the inspection is suppressed.

    You can find a list of inspections and their identifiers in the Supressing comments table. For example, to supress the Comment of exported element starts with the incorrect name inspection, use the GoCommentStartInspection identifier with the // noinspection comment. The full comment is // noinspection GoCommentStartInspection.

    Suppressing an inspection

Suppress an inspection from the Problems tool window

The Inspection Results tab of the Problems tool window shows the problems detected while running code analysis.

  • In the Inspection Results tab of the Problems tool window (appears once you run code analysis), right-click the inspection you want to suppress and select the necessary suppress action.

    Suppressing inspection in the Inspection Results tool window

Enable suppressed inspections

When you suppress an inspection, the IDE adds the //noinspection annotation before the selected symbol. For example, if you suppress an inspection for a statement, GoLand adds the annotation before this statement.

  • To re-enable a suppressed inspection, delete the //noinspection annotation.

    The //noinspection annotation before a method

Disable highlighting, but keep the fix

Inspections have severities according to which they highlight code problems in the editor. You can quickly disable code highlighting for an inspection without opening the settings. In this case, the inspection remains enabled and provides a fix, but the severity changes to No highlighting (fix available).

  1. Place the caret at a code element highlighted by an inspection in the editor and press Alt+Enter.

    A list with available fixes and context actions opens. Locate the inspection fix that is marked with Intention action icon.

  2. Click the button next to the fix to open the inspection's options and select Disable highlighting, keep fix.

    Disable highlighting, keep the fix

The name of the inspection for which you are changing the severity is written above the inspection's options.

If you want to restore the highlighting, press Ctrl+Alt+S to open the IDE settings and select Editor | Inspections. Find the necessary inspection in the list and change its severity as you like. For more information, refer to Change inspection severity in all scopes.

Change the highlighting level for a file

  • By default, GoLand highlights all detected code problems. Hover over the widget in the top-right corner of the editor and select another level from the Highlight list:

    • None: turn highlighting off.

    • Syntax: highlight syntax problems only.

    • All Problems: (default) highlight syntax problems and problems found by inspections.

  • You can also change the highlighting level from the main menu. Select or press Ctrl+Alt+Shift+H.

Suppressing comments

Name of the inspection

ID to use with the noinspection keyword

Unused constant

GoUnusedConstInspection

Unused global variable

GoUnusedGlobalVariableInspection

Unused exported function

GoUnusedExportedFunctionInspection

Unused function

GoUnusedFunctionInspection

Unused parameter

GoUnusedParameterInspection

Unused type parameter

GoUnusedTypeParameterInspection

Unused type

GoUnusedTypeInspection

Unused exported type

GoUnusedExportedTypeInspection

Disabled GOPATH indexing

GoDisabledGopathIndexingInspection

Bool condition

GoBoolExpressionsInspection

Self assignment

GoSelfAssignmentInspection

Empty declaration

GoEmptyDeclarationInspection

Redundant second index in slices

GoRedundantSecondIndexInSlicesInspection

Redundant blank argument in range

GoRedundantBlankArgInRangeInspection

Redundant types in composite literals

GoRedundantTypeDeclInCompositeLit

Redundant semicolon

GoRedundantSemicolonInspection

Redundant comma

GoRedundantCommaInspection

Redundant type conversion

GoRedundantConversionInspection

Redundant import alias

GoRedundantImportAliasInspection

Type can be omitted

GoVarAndConstTypeMayBeOmittedInspection

Empty slice declared using a literal

GoPreferNilSliceInspection

Comment of exported element starts with the incorrect name

GoCommentStartInspection

Exported element should have its own declaration

GoExportedOwnDeclarationInspection

Struct initialization without field names

GoStructInitializationWithoutFieldNamesInspection

Receiver has a generic name

GoReceiverNamesInspection

Name starts with a package name

GoNameStartsWithPackageNameInspection

Unsorted imports

GoUnsortedImportInspection

Error string should not be capitalized or end with punctuation

GoErrorStringFormatInspection

Comment has no leading space

GoCommentLeadingSpaceInspection

Usage of Snake_Case

GoSnakeCaseUsageInspection

Exported element should have a comment

GoExportedElementShouldHaveCommentInspection

Unit-specific suffix for 'time.Duration'

GoUnitSpecificDurationSuffixInspection

Type parameter is declared in lowercase

GoTypeParameterInLowerCaseInspection

Redundant 'true' in for loop condition

GoRedundantTrueInForConditionInspection

Reserved word used as name

GoReservedWordUsedAsNameInspection

Loop variables captured by the func literal

GoLoopClosureInspection

Imported package name as a name identifier

GoImportUsedAsNameInspection

Malformed struct tag

GoVetStructTagInspection

Impossible interface type assertion

GoVetImpossibleInterfaceToInterfaceAssertionInspection

Incorrect usage of 'fmt.Printf' and 'fmt.Println' functions

GoPrintFunctionsInspection

Shadowing variable

GoShadowedVarInspection

Division by zero

GoDivisionByZeroInspection

Incorrect 'strings.Replace' count argument

GoStringsReplaceCountInspection

Malformed build tag

GoBuildTagInspection

Incorrect usage of the 'sync/atomic' package

GoVetAtomicInspection

Locks mistakenly passed by value

GoVetCopyLockInspection

Invalid conversions of 'uintptr' to 'unsafe.Pointer'

GoVetUnsafePointerInspection

Incorrect usage of the 'errors.As' function

GoErrorsAsInspection

Unused function or method call result

GoUnusedCallResultInspection

Unhandled error

GoUnhandledErrorResultInspection

Nilness analyzer

GoNilnessInspection

Defer/go statement calls 'recover' or 'panic' directly

GoDeferGoInspection

Non-standard signature for well-known function names

GoStandardMethodsInspection

Exceeded shift expression

GoShiftInspection

'Unmarshal' is called with the incorrect argument

GoVetUnmarshalInspection

Integer to string type conversion

GoVetIntToStringConversionInspection

'context.CancelFunc' is not called

GoVetLostCancelInspection

'FailNow' in a non-test goroutine

GoVetFailNowInNotTestGoroutineInspection

Mixed value and pointer receivers

GoMixedReceiverTypesInspection

Irregular usage of 'iota'

GoIrregularIotaInspection

Direct comparison of errors

GoDirectComparisonOfErrorsInspection

Type assertion on errors fails on wrapped errors

GoTypeAssertionOnErrorsInspection

Missing 'case' statements for 'iota' consts in 'switch'

GoSwitchMissingCasesForIotaConstsInspection

Infinite 'for' loop

GoInfiniteForInspection

'defer' in the loop

GoDeferInLoopInspection

Assignment to a receiver

GoAssignmentToReceiverInspection

Unreachable code

GoUnreachableCodeInspection

Deprecated element

GoDeprecationInspection

Redundant parentheses

GoRedundantParensInspection

Unexported return type of the exported function

GoExportedFuncWithUnexportedTypeInspection

Unnecessarily exported identifier

GoUnnecessarilyExportedIdentifiersInspection

Malformed test function name

GoTestNameInspection

Usage of context.TODO()

GoContextTodoInspection

Usage of 'interface{}' as a type

GoInterfaceToAnyInspection

Fuzzing is supported starting with Go 1.18

GoFuzzingSupportInspection

Convert string literals

GoConvertStringLiteralsInspection

Leading whitespace in directive comment

GoLeadingWhitespaceInDirectiveCommentInspection

Missing trailing comma before a newline in a composite literal

GoMissingTrailingCommaInspection

Last modified: 05 November 2024