Skip to main content

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, and Examples.
  • 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 .feature files or directories containing .feature files to format.

Options:

  • --tab-width INTEGER: Number of spaces for indentation if not using tabs (default: 2). This option replaces the old --indent flag.
  • --use-tabs: Indent using tabs instead of spaces. If set, --tab-width is 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-tags where 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 0 if all files are well-formatted.
    • Exits with code 1 if one or more files would be reformatted or had file-specific processing issues (e.g., parsing errors).
    • Exits with code 123 if an internal error occurred in the formatter.
  • --version: Show the program's version number and exit.
  • --help: Show this message and exit.

Examples:

  1. Format a single file with 4 spaces for indentation:

    gherkin-formatter --tab-width 4 my_feature.feature
    
  2. Check if files in a directory are formatted correctly:

    gherkin-formatter --check features/
    
  3. Preview formatting for a file, aligning keywords to the right:

    gherkin-formatter --dry-run --alignment right my_feature.feature
    
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gherkin_formatter-0.1.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gherkin_formatter-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

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

Hashes for gherkin_formatter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5b18ca330468fcfd69359dad0498f69b4a229faaa70a92a1e442184b5f5088e8
MD5 ec736b46803ada851783acb2a817bf3b
BLAKE2b-256 5801f6d4d2ca43fc41f415d0d81e073b6f682008d7dbafd388bfa57ae7f95f75

See more details on using hashes here.

File details

Details for the file gherkin_formatter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gherkin_formatter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5e65d5eb659d6f62a9ceab449fadac82fa5d706451e2cb4e2a036340adca28f
MD5 fd1fcb78f2404e17327f02dfefb1c9e9
BLAKE2b-256 26fbd7da8b26b09fe8d32d63142c37c9504244bed123ea7fb2d926a42c606b12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page