Skip to main content

Formatter for Gherkin language

Project description

Reformat-gherkin

Test   Coverage Status

Maintainability   Codacy Badge

License: MIT   PyPI   Code style: black

Table of Contents

About

Reformat-gherkin automatically formats Gherkin files. It ensures a consistent look regardless of who wrote the file.

It can be used either as a command-line tool, or a pre-commit hook.

Installation

Install reformat-gherkin using pip.

pip install reformat-gherkin

It requires Python 3.7+ to run.

Usage

To get started straight away:

reformat-gherkin {source_file_or_directory}

You should get good results without specifying any options, as reformat-gherkin uses sensible defaults.

Command-line options

You can list the available options by running reformat-gherkin --help.

Usage: reformat-gherkin [OPTIONS] [SRC]...

  Reformat the given SRC files and all .feature files in SRC folders. If -
  is passed as a file, reformat stdin and print the result to stdout.

Options:
  --check                         Don't write the files back, just return the
                                  status. Return code 0 means nothing would
                                  change. Return code 1 means some files would
                                  be reformatted. Return code 123 means there
                                  was an internal error.

  -a, --alignment [left|right]    Specify the alignment of step keywords
                                  (Given, When, Then,...). If specified, all
                                  statements after step keywords are left-
                                  aligned, spaces are inserted before/after
                                  the keywords to right/left align them. By
                                  default, step keywords are left-aligned, and
                                  there is a single space between the step
                                  keyword and the statement.

  -n, --newline [LF|CRLF]         Specify the line separators when formatting
                                  files inplace. If not specified, line
                                  separators are preserved.

  --fast / --safe                 If --fast given, skip the sanity checks of
                                  file contents. [default: --safe]

  --single-line-tags / --multi-line-tags
                                  If --single-line-tags given, output
                                  consecutive tags on one line. If --multi-
                                  line-tags given, output one tag per line.
                                  [default: --single-line-tags]

  --tab-width INTEGER             Specify the number of spaces per
                                  indentation-level. [default: 2]

  --use-tabs                      Indent lines with tabs instead of spaces.
  --config FILE                   Read configuration from FILE.
  --version                       Show the version and exit.
  --help                          Show this message and exit.

Reformat-gherkin is a well-behaved Unix-style command-line tool:

  • it does nothing if no sources are passed to it;
  • it will read from standard input and write to standard output if - is used as the filename;
  • it only outputs messages to users on standard error;
  • it exits with code 0 unless an internal error occurred (or --check was used).

Config file

Reformat-gherkin can read project-specific default values for its command line options from a .reformat-gherkin.yaml file.

By default, reformat-gherkin looks for the config file starting from the common base directory of all files and directories passed on the command line. If it's not there, it looks in parent directories. It stops looking when it finds the file, or a .git directory, or a .hg directory, or the root of the file system, whichever comes first.

Example config file:

check: False
alignment: left
tab_width: 4

Version control integration

You can integrate reformat-gherkin into your version control workflow by using pre-commit. Once you have installed pre-commit, add this to the .pre-commit-config.yaml file in your repository:

repos:
  - repo: https://github.com/ducminh-phan/reformat-gherkin
    rev: stable
    hooks:
      - id: reformat-gherkin

Then run pre-commit install and you're ready to go.

Acknowledgements

This project is inspired by black. Some functions are taken from black's source code.

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

reformat-gherkin-3.0.1.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

reformat_gherkin-3.0.1-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file reformat-gherkin-3.0.1.tar.gz.

File metadata

  • Download URL: reformat-gherkin-3.0.1.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.8.14 Linux/5.15.0-1020-azure

File hashes

Hashes for reformat-gherkin-3.0.1.tar.gz
Algorithm Hash digest
SHA256 a25e89fac3b632a7db7a3f217f4bfdc0f9cf4d8333d3ae9a830b0270beba6f3b
MD5 3af6b6c594eabf524fbaf1b29a2e620a
BLAKE2b-256 7c666da6919eb32a12e73b7af0fe4f82feb98a2280de9783a17d488cf4bb1bc6

See more details on using hashes here.

File details

Details for the file reformat_gherkin-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: reformat_gherkin-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.8.14 Linux/5.15.0-1020-azure

File hashes

Hashes for reformat_gherkin-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 50c17a69e93b83b7f3a7c36a5a6265aa5c051c351fb46ab539e04333317a6791
MD5 e1325e2b582db5d603696437dbaa1bb4
BLAKE2b-256 bc9feedbc852e9f28cce0763ae9af973cb320c5463a2d4a07f90d51ac0573a81

See more details on using hashes here.

Supported by

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