What is gherkin-lint?
The gherkin-lint npm package is a linter for Gherkin files, which are used in Behavior-Driven Development (BDD) to describe software behaviors in a natural language format. The tool helps ensure that Gherkin files adhere to best practices and style guidelines, making them easier to read and maintain.
What are gherkin-lint's main functionalities?
Linting Gherkin Files
This feature allows you to lint Gherkin files to ensure they follow specified rules. The code sample demonstrates how to use gherkin-lint to check for empty scenarios in a Gherkin file.
const gherkinLint = require('gherkin-lint');
const config = { 'no-empty-scenarios': 'error' };
const results = gherkinLint.lint(['path/to/feature/file.feature'], config);
console.log(results);
Custom Rule Configuration
This feature allows you to configure custom rules for linting. The code sample shows how to set up multiple rules, such as checking for empty scenarios and duplicate feature names.
const gherkinLint = require('gherkin-lint');
const config = {
'no-empty-scenarios': 'error',
'no-dupe-feature-names': 'warn'
};
const results = gherkinLint.lint(['path/to/feature/file.feature'], config);
console.log(results);
Command Line Interface
The gherkin-lint package also provides a command-line interface for linting Gherkin files. The code sample demonstrates how to use the CLI with a configuration file.
npx gherkin-lint -c path/to/config.json path/to/feature/file.feature
Other packages similar to gherkin-lint
cucumber
Cucumber is a tool for running automated tests written in plain language. While it is primarily focused on executing tests, it also includes some linting capabilities for Gherkin files. However, its primary focus is on test execution rather than linting.
gherkin
The gherkin package is a parser for Gherkin language. It focuses on parsing and tokenizing Gherkin files rather than linting them. It can be used as a building block for creating custom linters or other tools that work with Gherkin files.
Gherkin lint
Uses Gherkin to parse feature files and runs linting against the default rules, and the optional rules you specified in your .gherkin-lintrc
file.
Available rules
Source code of the rules can be found in scr/rules
.
Default:
- Disallow multiple Feature definitions in the same file.
- Disallow multiple Background definition in the same file.
- Disallow empty feature files.
Optional:
- Disallow files with no scenarios.
- Disallow empty Feature name.
- Disallow empty Scenario name.
- Disallow duplicate Feature names.
- Disallow duplicate Scenario names.