Code Style. Go
Use this page to configure formatting options for Go files. When you change these settings, the Preview pane shows how this will affect your code.
Tabs and Indents
Configure code style for indents, TAB and SPACE characters.
Item | Description | ||||
---|---|---|---|---|---|
Use tab character | Use TAB characters instead of SPACE characters for indents. A TAB character appears when you press Tab. A SPACE character when you press Space. | ||||
Smart tabs | Use combination of TAB and SPACE characters depending on the context. | ||||
Tab size | Set the size of a single TAB character (in a number of SPACE characters). | ||||
Indent | Set the size of an indent (in a number of SPACE characters). Indent is a position of a text relative to the margin. In our case, the margin is a gutter with line numbers. | ||||
Continuation indent | Add a number of SPACE characters to an indent on a next line for a multiline expression. Consider the following example with a zero indent and aligned strings.
| ||||
Keep indents on empty lines | Keep indents if the line is empty. |
Wrapping and Braces
Configure wrapping options and the usage of braces.
Item | Description |
---|---|
Hard wrap at | Use the Hard wrap at field to specify a margin space required on the right side of an element. If you select the Default option, then a value of the right margin from the global settings is used. |
Wrap on typing | Use the Wrap on typing settings to specify how the edited text is fitted in the specified Hard wrap at:
|
Visual guides | Use the Visual guides field to specify multiple right margins. You can leave a default value or enter the number of spaces for your margin. If you want to specify several margins, enter numbers separated by comma. |
Function call arguments | Select wrapping options for function call arguments. In Go, function call arguments are the values that are passed to a function when it is called. You can select between the following options:
You can apply the previous options to opening and closing parentheses:
|
Composite literals | Select wrapping options for composite literals. In Go, a composite literal is a compact notation for creating a value of a composite type, which includes arrays, slices, maps, and structs. You can select between the following options:
You can apply the previous options to opening and closing parentheses:
|
Function parameters | Select wrapping options for function parameters. In Go, function parameters are variables that are declared as part of a function signature and are used to pass data to the function when it is called. The values passed to the function as arguments are assigned to the function's parameters, allowing the function to operate on the data. You can select between the following options:
You can apply the previous options to opening and closing parentheses:
|
Function result parameters | Select wrapping options for function parameters. In Go, a function can have one or more result parameters, which are declared in the function signature after the parameter list, and are used to return values from the function to the caller. The result parameters are specified using the return type(s) of the function. You can select between the following options:
You can apply the previous options to opening and closing parentheses:
|
Imports
Configure code style rules for the import
section.
Item | Description | ||||
---|---|---|---|---|---|
Use back quotes for imports | Replace double quotes with backquotes.
| ||||
Add parentheses for a single import | Add parentheses for the | ||||
Remove redundant import aliases | Removes the alias when the alias name matches dependency name. For example, the import (
logrus "github.com/sirupsen/logrus"
) | ||||
Sorting type | Select what style to use for sorting the import statements. You can select between the following options:
| ||||
Move all imports to a single declaration | Groups all
| ||||
Group packages from Go SDK | Group import statements that belong to Go SDK packages together. For example, import statements from packages like
Note that this setting does not move import statements together if they are separated by statements from other packages. To group all import statements in a single section, select Move all imports to a single group. | ||||
Group | Group import statement according to the option that you chose. You can select the following options:
|
Other
Item | Description | ||||
---|---|---|---|---|---|
Add a leading space to comments | Add a space between double slashes and a comment text.
To exclude comments that start with a certain prefixes, click the Add icon (), type the prefix, and click OK. | ||||
Column width for Fill paragraph | Specify the maximum number of characters allowed in a comment before the text is wrapped. The limit is applied to the comment text and redistributes lines, spaces, and line breaks in such a way so that the lines end up fitting within a certain maximum width. The default is 80 characters.
| ||||
On code reformat | Automatically run gofmt when code is reformatted. By default, to reformat code, press Control+Alt+L. |