Skip to content

A simple and lightweight (fe)ature (fi)le (fo)rmatter written in Python.

Notifications You must be signed in to change notification settings

rushwerks/feefifofum

Repository files navigation

feefifofum

Python Tests Ruff

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.

Formatting

The formatter follows a list of pre-defined rules outlined below.

New lines

  • Two new lines between scenarios
  • One new line between all steps

Indentation

  • Two spaces for indentation
  • Indent one level for each feature file keyword, resulting in:
    • Feature: Zero spaces
    • Scenario: Two spaces
    • Given/When/Then/And: Four spaces
    • Tables/step comments: Six spaces

Installation

Install feefifofum directly from GitHub by running the following command:

pip install git+https://github.com/rushwerks/[email protected]

Usage

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)

Output

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

Backup

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

Pre-commit

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

Table format

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