GoLand 2024.1 Help

Code Inspections in Go Template

This topic lists all GoLand code inspections available in Go Template.

You can toggle specific inspections or change their severity level on the Editor | Inspections page of settings  Ctrl+Alt+S.

Inspection

Description

Default Severity

Duplicate variable

Reports duplicate Go Template variables that are declared in the same scope.

Duplicating a variable reassigns the existing variable with the same name. This operation might lead to different unpredicatable issues.

Example:

{{$v := 0}}{{$v := 1}}{{$v}} is 0. {{/* evaluates to '1 is 0' */}} {{$v := 0}}{{$w := 1}}{{$v}} is 0. {{/* works as expected */}}

Error Error

Unknown variable

Reports usages of unknown variables in Go Templates.

Parsing of such templates will cause panic because variables must be declared before usage.

Example:

{{$v}} is zero. {{/* bad, $v is unknown */}} {{$v := 0}}{{$v}} is zero. {{/* good */}}

Error Error

Last modified: 11 February 2024