GoLand features robust, fast, and flexible static code analysis. It detects the language and runtimesyntax errors, suggests corrections and improvements.
GoLand performs code analysis by applying inspections to your code. Code inspections work for and other supported languages.
The inspections detect not only compiling errors, but also different code inefficiencies. Whenever you have some unreachable code, unused code, non-localized string, unresolved method, memory leaks or even spelling problems – you'll find it very quickly.
GoLand's code analysis is configurable. You can enable or disable each code inspection and change its severity, create profiles with custom sets of inspections, apply inspections differently in different scopes, suppress inspections in specific pieces of code, and more.
The analysis can be performed in several ways:
By default, GoLand analyses all open files and highlights all detected code issues right in the editor. On the right side of the editor you can see the analysis status of the whole file (the icon in the top-right corner).
The severity levels are the following: an error (), a warning , no issues found ().
Alternatively, you can run code analysis in a bulk mode for the specified scope, which can be as large as the whole project.
If necessary, you can apply a single code inspection in a specific scope.
For the majority of the detected code issues, GoLand provides quick fix suggestions. You can quickly review errors in a file by navigating from one highlighted line to another by pressing F2Shift+F2.
Inspection severity indicates how seriously the detected code issues impact the project and determines how the detected issues are highlighted in the editor. By default, each inspection has one of the following severity levels:
No highlighting, only fix
You can increase or decrease the severity level of each inspection. For example, you can force GoLand to display some warnings as errors or weak warnings. In a similar way, what is initially considered a weak warning can be displayed as a warning, an error, or just as a reference information.
You can also configure the color and font style used to highlight each severity level. Besides, you can create custom severity levels and set them for specific inspections.
If necessary, you can set different severity levels for the same inspection in different scopes.
All modifications to inspections mentioned above are saved in the inspection profile currently selected in the inspection settings and apply when this profile is used.
By default, all enabled code inspections apply to all project files. If necessary, you can configure each code inspection (enable or disable, change its severity level and options) individually for different scopes. Such configurations, like any other inspection settings, are saved and applied as part of a specific profile.
There may be complicated cases when an inspection has different configurations associated with different scopes. When such inspection is executed in a file belonging to some or all of these scopes, the settings of the highest priority scope-specific configuration are applied. The priorities are defined by the relative position of the inspection's scope-specific configuration in inspection settings: the uppermost configuration has the highest priority. The Everywhere else configuration always has the lowest priority.
Examples of code inspections
To see the list of available inspections, open Settings | Preferences (Ctrl+Alt+S) and navigate to .
The Unreachable code inspection detects parts of code that cannot be executed.
The Unhandled Error code inspection alerts you about functions or methods that can return an error value that is not handled in the code. In settings, you can change the severity level for each scope and, if necessary, exclude function names or method names for this inspection.