Registry / testing / gherkin-formatter

gherkin-formatter

JSON →
library1.2.2jsnpmunverified

A TypeScript library for formatting Gherkin AST models back into Gherkin feature file strings. Current stable version is 1.2.2, released under the Gherking organization. It provides a format() function that takes a Document AST node (from gherkin-ast) and optional FormatConfig options to control tag layout, line breaks, indentation, and compact output. Key differentiator: it is part of the gherking ecosystem, designed to work with gherkin-ast and gherkin-io for parsing, manipulating, and writing Gherkin documents programmatically.

npm install gherkin-formatter
INSTALL
IMPORT
SIG · GHERKIN-FORMATTER
G
gherkin-formatter
testingjavascriptv1.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

format
import { format } from 'gherkin-formatter'
const format = require('gherkin-formatter').format
ESM supported; also works with CommonJS require destructuring.
FormatConfig
import { FormatConfig } from 'gherkin-formatter'
import { FormatOptions } from 'gherkin-formatter'
The type was renamed from FormatOptions to FormatConfig in a prior version; FormatOptions is deprecated.
default
import gherkinFormatter from 'gherkin-formatter'
import { default } from 'gherkin-formatter'
Default export is undefined; use named exports.

Read a Gherkin file, parse to AST, format with custom options, and output the formatted Gherkin string.

import { format } from 'gherkin-formatter'; import { Document } from 'gherkin-ast'; import { read } from 'gherkin-io'; async function main() { const docs: Document[] = await read('./example.feature'); const options = { separateStepGroups: true, oneTagPerLine: true, compact: false, lineBreak: '\n', indentation: ' ' }; const formatted = format(docs[0], options); console.log(formatted); } main().catch(console.error);
Debug
Known issues
deprecatedFormatOptions has been renamed to FormatConfig.
fix
Use FormatConfig instead of FormatOptions in type annotations.
affects: >=1.1.0
gotchaThe format function expects a single Document node, not an array.
fix
Access the first element of the array returned by read(): format(docs[0], options).
affects: >=1.0.0
breakingChanged default indentation from four spaces to two spaces in version 1.2.0.
fix
Set indentation explicitly in options or update tests that rely on the old default.
affects: 1.2.0
gotchaRequires Node >=12.0.0; may not work on older Node versions.
fix
Upgrade Node to 12 or later.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'gherkin-ast'
Missing peer dependency gherkin-ast.
fix
npm install gherkin-ast
Property 'format' does not exist on type 'typeof import("gherkin-formatter")'
Using default import instead of named import.
fix
Use `import { format } from 'gherkin-formatter'` instead of `import gherkinFormatter from 'gherkin-formatter'`
TypeError: docs.map is not a function
Passing an array of Document objects to format, which expects a single Document.
fix
Call format on individual document: format(docs[0], options)
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
gherkin-astrequiredProvides the AST classes (Document, Scenario, etc.) that the formatter accepts as input.
debugoptionalUsed for debug logging; set DEBUG=gherkin-formatter* to see logs.
Agent activity
4 hits · last 30 days
node
4
Resources
gherkin-formatter — npm install gherkin-formatter · libregistry