npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gherkinfmt

v1.1.1

Published

Opinionated Gherkin formatter - zero configuration, one way to format

Readme

gherkinfmt

Opinionated Gherkin formatter - zero configuration, one way to format.

npm version Download - npm License - npm install size semantic-release

continuous integration release runnable codecov

Philosophy

Like Standard.js for JavaScript - no configuration, no debates. One way to format Gherkin/Cucumber feature files.

Installation

# npm
npm install gherkinfmt

# yarn
yarn add gherkinfmt

# pnpm
pnpm add gherkinfmt

# global install for CLI
npm install -g gherkinfmt

Usage

CLI

# Check if files are formatted (validates without modifying)
gherkinfmt --check file.feature

# Check multiple files with glob pattern
gherkinfmt --check "src/**/*.feature"

# Check all .feature files in current directory
gherkinfmt --check "*.feature"

# Check all .feature files in directory (recursive)
gherkinfmt --check src/

# Format files in-place (overwrites)
gherkinfmt --write file.feature

# Format multiple files with glob pattern
gherkinfmt --write "src/**/*.feature"

# Format all .feature files in directory (recursive)
gherkinfmt --write src/

# Show help
gherkinfmt --help

# Show version
gherkinfmt --version

Glob patterns support:

  • * - matches any characters except path separator
  • ** - matches any characters including path separator (recursive)
  • ? - matches single character
  • {a,b} - matches either pattern

Exit codes:

  • 0 - All files are formatted correctly (check) or formatted successfully (write)
  • 1 - Some files need formatting, errors occurred, or no mode specified

API

import { check, format } from 'gherkinfmt';

// Check if Gherkin string is formatted correctly
const isFormatted = check('Feature: My Feature\n');
console.log(isFormatted); // true or false

// Format Gherkin string
const formatted = format('Feature:My Feature');
console.log(formatted); // 'Feature: My Feature\n'

CommonJS

const { check, format } = require('gherkinfmt');

const formatted = format('Feature: My Feature');

Browser (UMD)

<script src="https://unpkg.com/gherkinfmt/dist/gherkinfmt.umd.js"></script>
<script>
  const formatted = gherkinfmt.format('Feature: My Feature');
</script>

Docker

# Check a file
docker run --rm -v $(pwd):/data ghcr.io/jojoee/gherkinfmt --check /data/file.feature

# Check all .feature files in a directory
docker run --rm -v $(pwd):/data ghcr.io/jojoee/gherkinfmt --check /data/

# Format a file
docker run --rm -v $(pwd):/data ghcr.io/jojoee/gherkinfmt --write /data/file.feature

Formatting Rules

These rules are not configurable - that's the point!

| Rule | Value | |------|-------| | Indentation | 2 spaces | | Feature keyword | No indentation | | Background/Scenario/Scenario Outline | 2 spaces | | Rule keyword | 2 spaces | | Steps (Given/When/Then/And/But/*) | 4 spaces | | Examples | 4 spaces | | Data tables | Aligned columns | | Doc strings | Preserved with media type | | Tags | One per line, before element | | Comments | Preserved in place | | Trailing whitespace | Removed | | Blank lines | Single between scenarios | | End of file | Single newline |

API Reference

check(input: string): boolean

Check if a Gherkin string is formatted correctly.

check('Feature: My Feature\n');  // true
check('Feature:My Feature');      // false (missing space)

format(input: string): string

Format a Gherkin string according to the opinionated rules.

format('Feature:My Feature');
// Returns: 'Feature: My Feature\n'

Gherkin Features Supported

  • Feature keyword
  • Background
  • Scenario
  • Scenario Outline with Examples
  • Steps (Given, When, Then, And, But, *)
  • Data tables (with column alignment)
  • Doc strings (triple quotes with media type)
  • Tags (@tag)
  • Comments (#)
  • Rule keyword (Gherkin 6+)
  • Descriptions (Feature, Scenario, Rule)
  • Unicode and special characters
  • Escaped characters in tables

Integration

Pre-commit Hook

# .husky/pre-commit
npx gherkinfmt --check "features/**/*.feature"

VS Code Task

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Check Gherkin",
      "type": "shell",
      "command": "npx gherkinfmt --check features/"
    }
  ]
}

CI/CD

# GitHub Actions
- name: Check Gherkin formatting
  run: npx gherkinfmt --check "features/**/*.feature"

Development

Commands

# Install dependencies
npm install

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Build
npm run build

# Build CLI
npm run build:cli

# Lint
npm run lint
# Run locally

# Check a single file
node bin/gherkinfmt.js --check resource/01-minimal.feature

# Check entire resource folder
node bin/gherkinfmt.js --check resource/

# Format a single file (writes changes)
node bin/gherkinfmt.js --write resource/all-cases.feature

# Format entire resource folder (writes changes)
node bin/gherkinfmt.js --write resource/

Related