Fee-fi-fo-fum (feefifofum
) is a simple and lightweight (fe)ature (fi)le (fo)rmatter written in Python.
A .feature
file is a plain-text file written in Gherkin syntax, and is used in Behavior Driven Development (BDD) to define test scenarios for software.
The formatter follows a list of pre-defined rules outlined below.
- Two new lines between scenarios
- One new line between all steps
- Two spaces for indentation
- Indent one level for each feature file keyword, resulting in:
Feature
: Zero spacesScenario
: Two spacesGiven
/When
/Then
/And
: Four spaces- Tables/step comments: Six spaces
Install feefifofum
directly from GitHub by running the following command:
pip install git+https://github.com/rushwerks/[email protected]
feefifofum
can run directly on feature files or directories containing feature files.
If directory paths are provided, then feature files in all subdirectories will also be formatted.
feefifofum <file> # Format a single file
feefifofum <file1> <file2> <file3> # Format multiple files
feefifofum . # Format all feature files in current directory and subdirectories
feefifofum <directory> # Format all feature files in specified directory and any subdirectories
feefifofum <directory1> <directory2> # Format all feature files in multiple directories (and any of their subdirectories)
In its default setting, feefifofum
will only log the total number of formatted and unchanged files to the console.
Files marked as 'unchanged' already meet the required formatting standard and therefore no changes are written to these files.
The --verbose
or -v
flag can be passed to log realtime information on which files have been formatted (or are unchanged), and overall progress.
feefifofum <file1> <file2> <file3> --verbose
If files do not meet the required formatting standards, feefifofum
will overwrite them with necessary changes.
The --backup
flag can be passed to create backups of the original files.
This works by creating a copy of the original file in the same directory, and appending a .bak
extension to the filename. Permissions of the original file will be preserved and file metadata will attempt to be preserved.
feefifofum <file> --backup --verbose
feefifofum
is also available as a pre-commit hook. It can be configured as follows:
- repo: https://github.com/rushwerks/feefifofum/
rev: v0.3.0
hooks:
- id: feefifofum
Feature files should have a single table per step (Given
/When
/Then
/And
). This assumption is used to identify tables, by tracking changes of pipe (|
) characters on each line.
Each row of a table must also:
- Start with pipe character
- End with a pipe character
- Have a consistent number of pipe characters
- Only use a single pipe character for each cell's boundary