Gherkin Formatting with EditorConfig¶
EditorConfig is a file format specification for
consistent coding styles maintained by EditorConfig.org,
usable by adding an .editorconfig file to your solution or project. Check
the EditorConfig support documentation of Visual Studio
for more details about EditorConfig files.
You can fine-tune the formatting for Gherkin files in your project by
tweaking settings in your .editorconfig file. These options control
indentation, table styling, and more for *.feature files, and apply the
same way in Visual Studio, VS Code, and Rider alike — no per-IDE variant of
the .editorconfig keys is needed. They feed the
Document & Table Formatting feature.
Supported Settings¶
Setting Name |
Description |
Value Type |
Default |
|---|---|---|---|
|
Indent child elements of Feature (Background, Rule, Scenario, Scenario Outline) |
boolean |
|
|
Indent child elements of Rule (Background, Scenario, Scenario Outline) |
boolean |
|
|
Indent steps in scenarios |
boolean |
|
|
Apply additional indentation to |
boolean |
|
|
Indent DataTable arguments within steps |
boolean |
|
|
Indent DocString arguments within steps |
boolean |
|
|
Indent the Examples block in Scenario Outlines |
boolean |
|
|
Indent the Examples table within Examples blocks |
boolean |
|
|
Number of spaces to pad table cells on each side |
integer |
|
|
Right-align numeric values in table cells |
boolean |
|
Sample .editorconfig for Gherkin Files¶
Below is an example of an .editorconfig section for *.feature files.
Note
The Gherkin file format supports non-ASCII characters only with UTF-8 format. In order to ensure that the feature files are saved as UTF-8, you can specify the charset setting in the EditorConfig file as shown in the example below.
[*.feature]
charset = utf-8
gherkin_indent_feature_children = true
gherkin_indent_steps = true
gherkin_indent_datatable = true
gherkin_indent_docstring = true
gherkin_indent_examples_table = true
gherkin_table_cell_padding_size = 2
gherkin_table_cell_right_align_numeric_content = true
Adjust the values above to match your project’s formatting needs.