Rules can either be specified in your gherklin.config.ts
file, or inline when you call
the Runner
Rule configuration takes the form of a string
key and a value. Every rule supports off
as a
value,
turning the rule off (which is the same as excluding it from the configuration).
However, depending on the rule, there may be more configuration values.
If a rule does not specify a severity, it will default to warn
.
The following is a list of rules and whether or not they are fixable with the fix
configuration
option.
Name | Rule | Fixable |
---|---|---|
Allowed Tags | allowed-tags |
❌ |
Indentation | indentation |
✅ |
Max Scenarios | max-scenarios |
❌ |
New Line at EOF | new-line-at-eof |
✅ |
No Background Only | no-background-only |
❌ |
No Dupe Features | no-dupe-features |
❌ |
No Dupe Scenarios | no-dupe-scenerios |
❌ |
No Similar Scenarios | no-similar-scenerios |
❌ |
No Empty File | no-empty-file |
❌ |
No Trailing Spaces | no-trailing-spaces |
✅ |
No Unnamed Scenarios | no-unnamed-scenarios |
❌ |
Keywords in Logical Order | keywords-in-logical-order |
❌ |
No Single Example Outline | no-single-example-outline |
❌ |
No Full Stop | no-full-stop |
✅ |
No Scenario Splat | no-scenario-splat |
❌ |
No Typographer Quotes | no-typographer-quotes |
✅ |
Background Setup Only | background-setup-only |
❌ |
Given After Background | given-after-backgroundy |
❌ |
No Inconsistent Quotes | no-inconsistent-quotes |
✅ |
Filename Snake Case | filename-snake-case |
❌ |
Filename Kebab Case | filename-kebab-case |
❌ |
Unique Examples | unique-examples |
❌ |
Feature Description | feature-description |
❌ |
Scenario Action | scenario-action |
❌ |
Scenario Verification | scenario-verification |
❌ |
Scenario Name Length | scenario-name-length |
❌ |
Restrict which tags are allowed in feature files by specifying a list. This rule checks for valid tags at the feature level and scenario level.
Examples
Enable the rule with arguments
export default {
rules: {
'allowed-tags': ['@development'],
},
}
Enable the rule and set severity
export default {
rules: {
'allowed-tags': ['error', '@development'],
}
}
Configure how many spaces are allowed for different Gherkin keywords.
Examples
Enable the rule with arguments
export default {
rules: {
indentation: {
feature: 1,
background: 3,
scenario: 3,
step: 5,
examples: 5,
given: 5,
when: 5,
then: 5,
and: 5,
but: 5,
exampleTableHeader: 7,
exampleTableBody: 7,
}
}
}
Enable the rule and set severity
export default {
rules: {
indentation: [
'error',
{
feature: 1,
background: 3,
scenario: 3,
step: 5,
examples: 5,
given: 5,
when: 5,
then: 5,
and: 5,
but: 5,
exampleTableHeader: 7,
exampleTableBody: 7,
}
]
}
}
Specify the maximum number of scenarios allowed per feature.
Examples
Enable the rule with arguments
export default {
rules: {
'max-scenarios': 2,
}
}
Enable the rule and set severity
export default {
rules: {
'max-scenarios': [
'error',
2,
]
}
}
Expect a new line at the end of each file.
Examples
Enable the rule
export default {
rules: {
'new-line-at-eof': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'new-line-at-eof': 'error',
}
}
Don't allow features which only have a background.
Examples
Enable the rule
export default {
rules: {
'no-background-only': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-background-only': 'error',
}
}
Don't allow features to have the same name across all files.
Examples
Enable the rule
export default {
rules: {
'no-dupe-features': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-dupe-features': 'error',
}
}
Don't allow scenarios to have the same name across all files.
Examples
Enable the rule
export default {
rules: {
'no-dupe-scenarios': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-dupe-scenarios': 'error',
}
}
Don't allow feature files to be empty.
Examples
Enable the rule
export default {
rules: {
'no-empty-file': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-empty-file': 'error',
}
}
Don't allow trailing spaces at the end of lines.
Examples
Enable the rule
export default {
rules: {
'no-trailing-spaces': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-trailing-spaces': 'error',
}
}
Expect every scenario to be named.
Examples
Enable the rule
export default {
rules: {
'no-unnamed-scenarios': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-unnamed-scenarios': 'error',
}
}
Asserts that keywords follow the logical order or Given, When, Then.
Examples
Enable the rule
export default {
rules: {
'keywords-in-logical-order': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'keywords-in-logical-order': 'error',
}
}
Compares each scenario with each other scenario to see if they are similar. Compares the Levenshtein distance between one scenarios keyword + text with the other scenarios keyword + text. The argument passed to this rule's configuration is the percentage threshold for similarity.
Examples
Enable the rule
export default {
rules: {
'no-similar-scenarios': 'on',
}
}
Enable the rule with arguments
export default {
rules: {
'no-similar-scenarios': 85,
}
}
Enable the rule and set severity
export default {
rules: {
'no-similar-scenarios': 'error',
}
}
Set severity and arguments
export default {
rules: {
'no-similar-scenarios': ['error', 99],
}
}
Checks Scenario Outlines that only have one example. These should be converted to simple Scenarios.
Examples
Enable the rule
export default {
rules: {
'no-single-example-outline': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-single-example-outline': 'error',
}
}
Full stops (period) end sentences and don't convey a flow of steps.
Examples
Enable the rule
export default {
rules: {
'no-full-stops': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-full-stops': 'error',
}
}
Splat steps (*) are useful for setup, which should occur in the background
Examples
Enable the rule
export default {
rules: {
'no-scenario-splat': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-scenario-splat': 'error',
}
}
"Smart quotes" can be a result of copy/pasting from other programs and may not be intended.
Examples
Enable the rule
export default {
rules: {
'no-typographer-quotes': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-typographer-quotes': 'error',
}
}
Enable the rule and set argument.
The argument is used as a replacement when the fix
option is specified.
export default {
rules: {
'no-typographer-quotes': ['error', "\""],
}
}
Background should be used for set up only, so should only include "Given" or splats (*).
Examples
Enable the rule
export default {
rules: {
'background-setup-only': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'background-setup-only': 'error',
}
}
If you have a background, it should be used to set up scenarios, so there's no need for scenarios to also use "Given"
Examples
Enable the rule
export default {
rules: {
'given-after-background': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'given-after-background': 'error',
}
}
Prefer consistency with quotes used.
Examples
Enable the rule
export default {
rules: {
'no-inconsistent-quotes': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'no-inconsistent-quotes': 'error',
}
}
Enable the rule and set argument.
The argument is used as a replacement when the fix
option is specified.
export default {
rules: {
'no-inconsistent-quotes': ['error', "\""],
}
}
File names should be in snake_case.
Examples
Enable the rule
export default {
rules: {
'filename-snake-case': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'filename-snake-case': 'error',
}
}
File names should be in kebab-case.
Examples
Enable the rule
export default {
rules: {
'filename-kebab-case': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'filename-kebab-case': 'error',
}
}
Examples should have a unique name if there are more than 1 in a scenario outline.
Examples
Enable the rule
export default {
rules: {
'unique-examples': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'unique-examples': 'error',
}
}
Features should have descriptions to outline what behaviour they are testing.
Examples
Enable the rule
export default {
rules: {
'feature-description': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'feature-description': 'error',
}
}
Scenarios should have a "When" to denote an action
Examples
Enable the rule
export default {
rules: {
'scenario-action': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'scenario-action': 'error',
}
}
Scenarios should have a "Then" to denote verification of an action
Examples
Enable the rule
export default {
rules: {
'scenario-verification': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'scenario-verification': 'error',
}
}
Scenarios should have a length no longer than specified.
Examples
Enable the rule
export default {
rules: {
'scenario-name-length': 'on',
}
}
Enable the rule and set severity
export default {
rules: {
'scenario-name-length': 'error',
}
}
Enable the rule and set args
export default {
rules: {
'scenario-name-length': ['error', 99],
}
}