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.
Use this page to configure formatting options for SQL files. When you change these settings, the Preview pane shows how this will affect your code.
Item | Description |
---|---|
Use tab character | Use the Tab key for indentation. When the checkbox is cleared, IntelliJ IDEA uses spaces instead of tabs. By default, the checkbox is cleared. |
Smart tabs |
The Smart tabs checkbox is available if the Use tab character option is enabled. By default, the checkbox is cleared. |
Tab size | In this field, specify the number of spaces included in a tab. Default value: |
Indent | In this field, specify the number of spaces to be inserted for each indent level. Default value: |
Continuation indent | Specify the indentation for lines that continue from the previous line, making it clear that they are part of the same statement or block of code. Continuation indents are used when a single statement is too long to fit on one line. Default value: |
Keep indents on empty lines | If this checkbox is selected, IntelliJ IDEA will keep indents on the empty lines as if they contained some code. If this checkbox is cleared, IntelliJ IDEA will delete the tab characters and spaces. By default, the checkbox is cleared. |
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 backquotes 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 packages 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 Reformat Code action | Automatically run gofmt when code is reformatted. By default, to reformat code, press Ctrl+Alt+L. |