Auto-Fix¶
behave-lint can automatically fix certain rule violations in your
.feature files.
Usage¶
# Apply safe fixes only
behave-lint features/ --fix
# Apply safe and unsafe fixes
behave-lint features/ --fix --unsafe-fixes
Safe vs. unsafe fixes¶
| Category | Description |
|---|---|
| Safe | Deterministic transformations that cannot change test semantics. Applied with --fix. |
| Unsafe | Transformations that may change behavior or require human review. Only applied with --unsafe-fixes. |
Rules with auto-fix support¶
Safe fixes¶
| Rule | Fix |
|---|---|
| BC004 (invalid-tag-syntax) | Replace invalid characters in tags with _. |
| BD004 (step-parameter-convention) | Convert {param} to <param> when both conventions are mixed. |
| BD005 (step-trailing-punctuation) | Remove trailing punctuation from step text. |
| BS001 (tag-casing) | Convert tags to lowercase snake_case. |
| BS006 (step-keyword-casing) | Capitalize step keywords (e.g., given → Given). |
| BS007 (trailing-whitespace) | Remove trailing whitespace from lines. |
| BS008 (tab-indentation) | Replace tab indentation with spaces (2 per level). |
Unsafe fixes¶
| Rule | Fix |
|---|---|
| BS002 (keyword-ordering) | Reorder steps to Given → When → Then. |
| BS003 (step-phrasing) | Rewrite first-person steps to third-person. |
| BS004 (background-name) | Insert Background: Common setup as a placeholder name. |
| BS005 (feature-description) | Insert a template As a / I want / So that description. |
| BP001 (missing-scenario-tags) | Insert @smoke tag before scenarios without tags. |
| BP005 (missing-examples-name) | Append Valid values name to unnamed Examples sections. |
| BP006 (missing-feature-description) | Insert a template As a / I want / So that description after the Feature line. |
Conflict resolution¶
When multiple fixes target overlapping lines in the same file,
behave-lint applies only the first fix and skips conflicting ones.
A warning is printed for each skipped fix.
Examples¶
Fix tag casing (BS001)¶
Before:
After --fix:
Fix invalid tag syntax (BC004)¶
Before:
After --fix:
Fix trailing punctuation (BD005)¶
Before:
After --fix:
Fix mixed parameter convention (BD004)¶
Before:
After --fix:
Fix step keyword casing (BS006)¶
Before:
After --fix:
Fix trailing whitespace (BS007)¶
Before:
After --fix:
Fix tab indentation (BS008)¶
Before:
After --fix:
Fix missing scenario tags (BP001)¶
Before:
After --fix --unsafe-fixes:
Fix missing examples name (BP005)¶
Before:
After --fix --unsafe-fixes:
Fix missing feature description (BP006)¶
Before:
After --fix --unsafe-fixes: