A standalone linter for Gherkin feature files to enforce grammar and best practices
Project description
bdd-lint
A linter for Behave BDD scenarios to enforce grammar and best practices.
Features
- All major rules from gherkin-lint
- Custom configuration via
.bdd-lint.yml - Enable/disable rules and set options
- Support for custom user-defined rules in
custom_rules/ - CLI config selection:
bdd-lint <feature-file> [--config <config-file>]
Supported Rules
GivenPastTenseRule: Enforces past tense for 'Given' steps.
- WhenPresentTenseRule: Enforces present tense for 'When' steps.
- ThenFutureTenseRule: Enforces future verbs (should, will, shall) for 'Then' steps.
- OneWhenThenRule: Restricts each scenario to exactly one When and one Then step.
- ThirdPersonRule: Enforces third-person perspective in steps.
- TenseConsistencyRule: Ensures consistent tense usage across Given/When/Then.
- NoEmptyScenariosRule: Flags scenarios with no steps.
- NoUnnamedFeaturesRule: Flags features without a name.
- NoUnnamedScenariosRule: Flags scenarios without a name.
- NoDuplicateScenariosRule: Flags duplicate scenario names.
- NoDuplicateStepRule: Flags duplicate steps within a scenario.
- NoScenarioOutlinesWithoutExamplesRule: Flags scenario outlines missing Examples.
- NoStepKeywordInStepTextRule: Flags steps containing step keywords in their text.
- NoMultilineStepRule: Flags steps that span multiple lines.
- NoTagsOnBackgroundsRule: Flags tags on Background sections.
- ConsistentStepKeywordOrderRule: Ensures step keywords appear in the order: Given, When, Then.
- LowerCaseFeatureNameRule: Enforces feature names to be lower case.
- LowerCaseScenarioNameRule: Enforces scenario names to be lower case.
- MaxScenariosPerFileRule: Flags if the number of scenarios in a file exceeds a threshold.
- MaxStepsPerScenarioRule: Flags if the number of steps in a scenario exceeds a threshold.
- RequiredTagsRule: Flags scenarios missing required tags.
- TagsFormatRule: Flags tags that do not match a required format.
Usage
bdd-lint path/to/feature_file.feature
bdd-lint path/to/feature_file.feature --config custom_config.yml
# Example: output as JSON
bdd-lint path/to/feature_file.feature --json
Testing
Run the unit test suite with pytest:
pytest -q
The project includes a set of unit tests under tests/unit/ that exercise the parser, each rule, the NLP helper heuristics and the configuration verifier.
Configuration
Create a .bdd-lint.yml file in your project root:
rules:
GivenPastTenseRule: true
MaxScenariosPerFileRule: true
options:
MaxScenariosPerFileRule:
max_scenarios: 5
Custom Rules
Place your custom rule Python files in the custom_rules/ directory. Each file should define a class named in CamelCase matching the filename, inheriting from BaseRule.
Example: custom_rules/my_custom_rule.py
from bdd_lint.rules.base_rule import BaseRule
class MyCustomRule(BaseRule):
def check(self, scenario):
# Custom logic
return []
Requirements
- Python 3.7+
- textblob, spacy, nltk, pytest, pytest-bdd, gherkin-official
- NLTK/TextBlob corpora and spaCy model are auto-downloaded on install
Notes:
- The library ships with a lightweight NLP helper in
bdd_lint.utils.nlpwhich falls back to fast heuristics when TextBlob/spaCy are not available. This keeps tests fast and deterministic. - Use the
bdd_lint.config_verifier.verify_confighelper to validate.bdd-lint.ymlfiles programmatically. - The CLI returns human-readable messages by default or a JSON array of issue objects when
--jsonis used. Each issue is represented by thebdd_lint.models.issue.Issuedataclass and includesrule,message,scenario,line, andseveritykeys.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bdd_lint-0.1.0.tar.gz.
File metadata
- Download URL: bdd_lint-0.1.0.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af23b9d4eefe19cb057fc00577514b77ec1933325347567d057d0f6e4059d88f
|
|
| MD5 |
42486c5eb7ae2cadd630db4ac3547057
|
|
| BLAKE2b-256 |
0c3705731ef73689e32252b97f46fbcff75fcea83041c619005c4ca9437cf3db
|
File details
Details for the file bdd_lint-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bdd_lint-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed67813b5be905144e797e8a70efea39ea35c4996e2522751d73a017cd100cd0
|
|
| MD5 |
667c71e72dacf62d487d7d4e14c72cc4
|
|
| BLAKE2b-256 |
ffb653959bdc6bc338cbeb461a73dd5b28da984c3d2f4e0b5146a3cc1df899bd
|