gherkin-lint-ts

raw JSON →
5.0.6 verified Fri May 01 auth: no javascript

Gherkin feature linter written in TypeScript, based on the original gherkin-lint project. Provides linting for .feature files using configurable rules, with support for custom TypeScript rules and error levels (Error/Warn). Current stable version is 5.0.6. Release cadence is irregular. Key differentiators: TypeScript support for writing custom rules, pretty terminal output, fixed issues from the original library, and output directed to process.stdout.

error Error: Cannot find module 'gherkin'
cause Missing peer dependency 'gherkin'.
fix
Run 'npm install gherkin' or 'yarn add gherkin'.
error TypeError: lint is not a function
cause Using incorrect import (e.g., require('gherkin-lint-ts') instead of named import).
fix
Use import { lint } from 'gherkin-lint-ts'.
error ERROR: No rules configured in .gherkin-lintrc
cause Configuration file exists but is missing the 'rules' key or is empty.
fix
Add a 'rules' object with at least one rule to .gherkin-lintrc.
breaking The 'lint' function is now asynchronous (returns a Promise) in v5.
fix Use await or .then() when calling lint().
deprecated The 'check' function is deprecated; use 'lint' instead.
fix Replace check() with lint().
gotcha Configuration file must be named `.gherkin-lintrc` and placed in the project root; the library does not search up the directory tree.
fix Ensure the config file is in the root directory of your project.
breaking Custom rules written in JavaScript are no longer supported; they must be written in TypeScript.
fix Rewrite custom rules in TypeScript.
gotcha The 'indentation' rule uses tabs by default instead of spaces.
fix Specify 'indentation': { 'Feature': 'spaces', 'Scenario': 2 } in config.
deprecated The 'new-line-at-eof' rule is deprecated; use the 'eof-newline' rule instead.
fix Replace 'new-line-at-eof' with 'eof-newline' in config.
npm install gherkin-lint-ts
yarn add gherkin-lint-ts
pnpm add gherkin-lint-ts

Shows how to import and use the linter with a config object, linting .feature files and printing results.

import { lint } from 'gherkin-lint-ts';

const config = {
  rules: {
    'no-tags-on-backgrounds': 'error',
    'name-length': { Feature: { min: 1, max: 100 } }
  }
};

const results = await lint(['path/to/features/**/*.feature'], config);
console.log(JSON.stringify(results, null, 2));