Allows restricting the maximum number of steps in a scenario, scenario outline and background
use-and
Disallows repeated step names requiring use of And instead
keywords-in-logical-order
Requires that Given, When and Then appear in logical sequence
* These rules cannot be turned off because they detect undocumented cucumber functionality that causes the gherkin parser to crash.
Rule Configuration
The not-configurable rules are turned on by default and cannot be turned off. Configurable rules can be customized using a file.
The configurable rules are off by default. To turn them on, you will need to create a json file, where you specify the name of each rule and its desired state (which can be error, warn or off). E.g.,
{
"no-unnamed-features": "error"
}
will turn on the no-unnamed-features rule.
allowed-tags
allowed-tags should be configured with the list of allowed tags and patterns:
PascalCase - first letter of each word capitalized (no spaces) e.g. "MyFancyFeature.feature"
Title Case - first letter of each word capitalized (with spaces) e.g. "My Fancy Feature.feature"
camelCase - first letter of each word capitalized, except first e.g. "myFancyFeature.feature"
kebab-case - all lowercase, hyphen-delimited e.g. "my-fancy-feature.feature"
snake_case - all lowercase, underscore-delimited e.g. "my_fancy_feature.feature"
no-restricted-patterns
no-restricted-patterns is a list of exact or partial patterns whose matches are dissallowed in feature name and description, and in background, scenario and scenario outline name, description and steps.
All patterns are treated as case insensitive.
The rule can be configured like this:
{
"no-restricted-patterns": ["error", {
"Global": [
"^globally restricted pattern"
],
"Feature": [
"poor description",
"validate",
"verify"
],
"Background": [
"show last response",
"a debugging step"
],
"Scenario": [
"show last response",
"a debugging step"
]
}]
}
Notes:
Step keywords Given, When, Then and And should not be included in the patterns.
Description violations always get reported in the Feature/Scenario/etc definition line. This is due to the parsed gherkin tree not having information about which line the description appears.
indentation
indentation can be configured in a more granular level and uses following rules by default:
Expected indentation for Feature, Background, Scenario, Examples heading: 0 spaces
Expected indentation for Steps and each example: 2 spaces
You can override the defaults for indentation like this:
There is no need to override all the defaults, as is done above, instead they can be overriden only where required. Step will be used as a fallback if the keyword of the step, eg. 'given', is not specified. If feature tag is not set then Feature is used as a fallback, and if scenario tag is not set then Scenario is used as a fallback.
This feature is able to handle all localizations of the gherkin steps.
max-scenarios-per-file
The max-scenarios-per-file supports some configuration options:
maxScenarios (number) the maximum scenarios per file after which the rule fails - defaults to 10
countOutlineExamples (boolean) whether to count every example row for a Scenario Outline, as opposed to just 1 for the whole block - defaults to true
The configuration looks like this (showing the defaults):
new-line-at-eof can be configured to enforce or disallow new lines at EOF.
To enforce new lines at EOF:
{
"new-line-at-eof": ["error", "yes"]
}
To disallow new lines at EOF:
{
"new-line-at-eof": ["error", "no"]
}
no-dupe-scenario-names
no-dupe-scenario-names can be configured to search for duplicates in each individual feature or amongst all feature files.
To enable searching for duplicates in each individual feature (same scenario name in different features won't raise an error) you need to configure the rule like this:
The default case is testing against all the features (same scenario name in different features will raise an error). To get that behavor use the following configuration:
scenario-size lets you specify a maximum step length for scenarios and backgrounds. The Scenario configuration applies to both scenarios and scenario outlines:
The default name for the configuration file is .gherkin-lintrc and it's expected to be in your working directory.
The file contents must be valid JSON, though it does allow comments.
If you are using a file with a different name or a file in a different folder, you will need to specify the -c or --config option and pass in the relative path to your configuration file. Eg: gherkin-lint -c path/to/configuration/file.extention
You can find an example configuration file, that turns on all of the rules in the root of this repo (.gherkin-lintrc).
Ignoring Feature Files
There are 2 ways you can specify files that the linter should ignore:
Add a .gherkin-lintignore file in your working directory and specify one glob pattern per file line
Use the command line option-i or --ignore, pass in a comma separated list of glob patterns. If specified, the command line option will override the .gherkin-lintignore file.
Custom rules
You can specify one more more custom rules directories by using the -d or --dirs command line option. Rules in the given directories will be available additionally to the default rules.
Paths can either be absolute or relative to the current working directory.
Have a look at the src/rules/ directory for examples; The no-empty-file rule is a good example to start with.