GoLand 2019.1 Help

Configuring code style

If certain coding guidelines exist in a company, one has to follow these guidelines when creating source code. GoLand helps you maintain the required code style.

Code styles are defined at the project level and at the IDE level (global).

  • At the project level, settings are grouped under the Project scheme, which is predefined and is marked in bold. The Project style scheme is applied to the current project only.

    You can copy the Project scheme to the IDE level, using the Copy to IDE command.

  • At the IDE level, settings are grouped under the predefined Default scheme (marked in bold), and any other scheme created by the user by the Duplicate command (marked as plain text). Global settings are used when the user doesn't want to keep code style settings with the project and share them.

    You can copy the IDE scheme to the current project, using the Copy to Project command.

Configure code style for a language

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Editor | Code Style and open the page of your programming language.

  2. Choose the code style scheme to be used as the base for your custom coding style for the selected language.

  3. Browse through the tabs of the selected language page, and configure code style preferences for it.

Copy code style settings from other languages

For most of the supported languages, you can copy code style settings from other languages or frameworks.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Editor | Code Style and open the page of your programming language.

  2. From the list that appears, select the language to copy the code style from.

Disable code formatting in a scope

  1. In Settings/Preferences (Ctrl+Alt+S), select Editor | Code Style.

  2. Click Formatter Control.

  3. Ensure that you selected a right scheme in the Scheme list.

  4. In the Do not format, optimize imports, arrange code pane, Click Add.

  5. In the Scopes dialog, click Add and select a scope. Select Local if the scope is intended for a personal use only. If you plan to share settings with team members, select Shared.

  6. Click OK.

  7. In the project tree, select the folder where you want to disable formatting and click Include .

  8. Click OK.

Configure the code style for a project using EditorConfig

Before you start working with EditorConfig, make sure that the EditorConfig plugin is enabled. The plugin is bundled with GoLand and is activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings / Preferences Dialog as described in Managing plugins.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Editor | Code Style and make sure the Enable EditorConfig Support checkbox is selected.

  2. In the project tree, right-click a directory where you want to create the EditorConfig settings file and select New | File.

  3. In the dialog that opens, enter .editorconfig and click OK.

    GoLand creates an EditorConfig settings file and displays a notification in the popup.

    Every time you open a file, the EditorConfig plugin looks for a file named .editorconfig in the directory of the opened file and in every parent directory. A search for .editorconfig files will stop if the root file path is reached or an EditorConfig file with root = true is found. Therefore, if you want to use the IDE settings instead of the EditorConfig settings, clear the Enable EditConfig Support checkbox in Editor | Code Style that is selected by default.

  4. Define the code style settings and save your .editorconfig (Ctrl+S) to immediately apply the settings to your project. The EditorConfig code style configuration overrides the code style configuration in the GoLand settings.

Last modified: 17 May 2019

See Also