A command-line tool to format Gherkin .feature files.
Project description
Gherkin Formatter
A Python command-line utility to format Gherkin (.feature) files, similar to how black formats Python files. This tool helps maintain consistent styling in your BDD feature specifications.
Features
- Consistent indentation for all Gherkin keywords (
Feature,Scenario,Given,When,Then, etc.). - Alignment of keywords within step blocks (Given/When/Then).
- Flexible tag formatting (single-line or multi-line).
- Automatic formatting of Data Tables with column alignment.
- Pretty-printing for JSON content within DocStrings.
- Support for
Rule,Background,Scenario Outline, andExamples. - Preserves all data; only formatting is changed.
Installation
You can install the Gherkin Formatter using pip:
pip install gherkin-formatter
Usage
gherkin-formatter [OPTIONS] [FILES_OR_DIRECTORIES...]
Arguments:
FILES_OR_DIRECTORIES...: One or more.featurefiles or directories containing.featurefiles to format.
Options:
--tab-width INTEGER: Number of spaces for indentation if not using tabs (default: 2). This option replaces the old--indentflag.--use-tabs: Indent using tabs instead of spaces. If set,--tab-widthis typically ignored by the formatter for indentation character, but may influence display width in some editors.-a, --alignment [left|right]: Alignment for keywords (Given, When, Then, etc.) within a block of steps.left: Left-aligns keywords (default).right: Right-aligns keywords based on the longest keyword in the current block.
--multi-line-tags: Formats tags each on a new line, indented. Default is--single-line-tagswhere all tags for an element are on a single line.--dry-run: Preview changes without modifying files. The formatted output (if different) will be printed to the console.--check: Check if files are formatted correctly. No files are changed.- Exits with code
0if all files are well-formatted. - Exits with code
1if one or more files would be reformatted or had file-specific processing issues (e.g., parsing errors). - Exits with code
123if an internal error occurred in the formatter.
- Exits with code
--version: Show the program's version number and exit.--help: Show this message and exit.
Examples:
-
Format a single file with 4 spaces for indentation:
gherkin-formatter --tab-width 4 my_feature.feature
-
Check if files in a directory are formatted correctly:
gherkin-formatter --check features/
-
Preview formatting for a file, aligning keywords to the right:
gherkin-formatter --dry-run --alignment right my_feature.feature
-
Format a file using tabs for indentation and multi-line tags:
gherkin-formatter --use-tabs --multi-line-tags my_feature.feature
Development
This project uses pytest for testing.
To run tests:
pytest
Contributions
Contributions are welcome! Please open an issue or submit a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gherkin_formatter-0.1.0.tar.gz.
File metadata
- Download URL: gherkin_formatter-0.1.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b18ca330468fcfd69359dad0498f69b4a229faaa70a92a1e442184b5f5088e8
|
|
| MD5 |
ec736b46803ada851783acb2a817bf3b
|
|
| BLAKE2b-256 |
5801f6d4d2ca43fc41f415d0d81e073b6f682008d7dbafd388bfa57ae7f95f75
|
File details
Details for the file gherkin_formatter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gherkin_formatter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5e65d5eb659d6f62a9ceab449fadac82fa5d706451e2cb4e2a036340adca28f
|
|
| MD5 |
fd1fcb78f2404e17327f02dfefb1c9e9
|
|
| BLAKE2b-256 |
26fbd7da8b26b09fe8d32d63142c37c9504244bed123ea7fb2d926a42c606b12
|