API Reference¶
Auto-generated API documentation from source code docstrings.
behave_lint
¶
behave-lint — A fast, opinionated, extensible linter for Gherkin .feature files.
This package provides static analysis for Behave BDD projects, consuming behave-model as its single source of truth.
Public API is defined in API.md. Only names explicitly exported here are considered stable and publicly supported.
AutoFixCapability
¶
Bases: Enum
Declares a rule's auto-fix support.
Members
NONE: Not fixable. SAFE: Fix does not change semantics. UNSAFE: Fix may change semantics.
Source code in behave_lint/models/enums.py
Category
¶
Bases: Enum
Groups rules by concern (what kind of problem).
Members
CORRECTNESS: Definitively wrong structures. STYLE: Stylistic conventions. COMPLEXITY: Overly complex specifications. CONSISTENCY: Cross-file consistency. PEDANTIC: Strict best practices (opt-in). STEP_DEFINITIONS: Cross-reference with step defs.
Source code in behave_lint/models/enums.py
code
property
¶
Single-letter category code used in rule IDs.
Returns:
| Type | Description |
|---|---|
str
|
The category code: C, S, X, K, P, or D. |
default_severity
property
¶
Default severity for rules in this category.
Returns:
| Type | Description |
|---|---|
Severity
|
The default Severity for the category. |
from_code(code)
classmethod
¶
Parse a single-letter code into a Category member.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Single uppercase letter (C, S, X, K, P, D). |
required |
Returns:
| Type | Description |
|---|---|
Category
|
The matching Category member. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the code does not match any member. |
Source code in behave_lint/models/enums.py
from_string(value)
classmethod
¶
Parse a string into a Category member.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Case-insensitive category string. |
required |
Returns:
| Type | Description |
|---|---|
Category
|
The matching Category member. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string does not match any member. |
Source code in behave_lint/models/enums.py
Config
dataclass
¶
Resolved configuration for a lint run.
Attributes:
| Name | Type | Description |
|---|---|---|
select |
list[str]
|
Rule IDs to enable (empty = all defaults). |
ignore |
list[str]
|
Rule IDs to disable. |
profile |
str
|
Profile name applied to this config (e.g. "recommended"). |
group |
list[str]
|
Group names applied to this config (e.g. ["correctness", "style"]). |
severity_overrides |
dict[str, Severity]
|
Per-rule severity overrides. |
output |
str
|
Output format(s), comma-separated. |
output_file |
str | None
|
Output file path (None = stdout). |
paths |
list[str]
|
Default paths to lint. |
exclude |
list[str]
|
Paths to exclude from linting. |
step_definitions |
str | None
|
Step definitions directory, or None. |
cache |
bool
|
Whether to enable caching. |
cache_dir |
str
|
Cache directory path. |
plugins |
dict[str, bool]
|
Plugin enable/disable map. |
rule_params |
dict[str, dict[str, object]]
|
Per-rule parameters. |
fail_on |
Severity
|
Minimum severity that causes non-zero exit. |
max_warnings |
int
|
Max warnings before exit code is non-zero (-1 = no limit). |
Source code in behave_lint/models/config.py
get_severity(rule_id, default)
¶
Get the effective severity for a rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_id
|
str
|
The rule ID. |
required |
default
|
Severity
|
Default severity if no override exists. |
required |
Returns:
| Type | Description |
|---|---|
Severity
|
The severity from overrides, or the default. |
Source code in behave_lint/models/config.py
is_rule_enabled(rule_id)
¶
Check if a rule is enabled given select/ignore lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_id
|
str
|
The rule ID to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the rule is enabled, False if explicitly ignored. |
bool
|
If select is non-empty, only selected rules are enabled. |
Source code in behave_lint/models/config.py
Diagnostic
dataclass
¶
A single issue found by a rule.
Attributes:
| Name | Type | Description |
|---|---|---|
rule_id |
str
|
Stable rule identifier (e.g., "BC001"). |
severity |
Severity
|
Severity level (effective, after user overrides). |
message |
str
|
Human-readable description of the issue. |
file_path |
str
|
Path to the .feature file. |
line |
int
|
1-based line number where the issue starts. |
column |
int | None
|
1-based column number, or None. |
end_line |
int | None
|
End line for multi-line issues, or None. |
end_column |
int | None
|
End column for multi-line issues, or None. |
suggestion |
str | None
|
Human-readable fix suggestion, or None. |
doc_url |
str | None
|
URL to rule documentation, or None. |
category |
Category
|
Rule category. |
Source code in behave_lint/models/diagnostic.py
is_error
property
¶
Whether this diagnostic has ERROR severity.
Returns:
| Type | Description |
|---|---|
bool
|
True if severity is ERROR, False otherwise. |
is_info
property
¶
Whether this diagnostic has INFO severity.
Returns:
| Type | Description |
|---|---|
bool
|
True if severity is INFO, False otherwise. |
is_warning
property
¶
Whether this diagnostic has WARNING severity.
Returns:
| Type | Description |
|---|---|
bool
|
True if severity is WARNING, False otherwise. |
location
property
¶
Formatted location string for display.
Returns:
| Type | Description |
|---|---|
str
|
A string like "features/login.feature:15:3" or |
str
|
"features/login.feature:15". |
__post_init__()
¶
Validate field constraints after initialization.
Source code in behave_lint/models/diagnostic.py
FixCost
¶
Bases: Enum
Estimated effort to fix a diagnostic.
Members
TRIVIAL: Minimal effort (e.g., whitespace). LOW: Quick fix (e.g., rename). MEDIUM: Requires some thought (e.g., restructure scenario). HIGH: Significant effort (e.g., rewrite feature file).
Source code in behave_lint/models/enums.py
LintResult
dataclass
¶
Result of a lint run.
Attributes:
| Name | Type | Description |
|---|---|---|
diagnostics |
list[Diagnostic]
|
All diagnostics, sorted by file/line/rule. |
summary |
LintSummary
|
Execution summary. |
exit_code |
int
|
Exit code (0, 1, or 2). |
fixes |
list[FixEdit]
|
Auto-fix edits collected during the run (if any). |
Source code in behave_lint/models/lint_result.py
has_diagnostics
property
¶
Whether any diagnostics were produced.
Returns:
| Type | Description |
|---|---|
bool
|
True if the diagnostics list is non-empty. |
has_errors
property
¶
Whether any diagnostic has ERROR severity.
Returns:
| Type | Description |
|---|---|
bool
|
True if at least one error diagnostic exists. |
passed
property
¶
Whether the lint run passed (exit code 0).
Returns:
| Type | Description |
|---|---|
bool
|
True if exit_code is 0. |
LintSummary
dataclass
¶
Execution summary for a lint run.
Attributes:
| Name | Type | Description |
|---|---|---|
total_files |
int
|
Number of files analyzed. |
files_with_issues |
int
|
Number of files with at least one diagnostic. |
total_diagnostics |
int
|
Total diagnostics produced. |
error_count |
int
|
Diagnostics with severity ERROR. |
warning_count |
int
|
Diagnostics with severity WARNING. |
info_count |
int
|
Diagnostics with severity INFO. |
rules_executed |
int
|
Number of rules that ran. |
duration_ms |
float
|
Execution time in milliseconds. |
cache_hits |
int
|
Number of cache hits. |
cache_misses |
int
|
Number of cache misses. |
Source code in behave_lint/models/lint_result.py
from_diagnostics(diagnostics, *, total_files=0, files_with_issues=0, rules_executed=0, duration_ms=0.0, cache_hits=0, cache_misses=0)
classmethod
¶
Build a summary from a list of diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostics
|
list[Diagnostic]
|
The diagnostics produced by the run. |
required |
total_files
|
int
|
Number of files analyzed. |
0
|
files_with_issues
|
int
|
Number of files with issues. |
0
|
rules_executed
|
int
|
Number of rules that ran. |
0
|
duration_ms
|
float
|
Execution time in milliseconds. |
0.0
|
cache_hits
|
int
|
Number of cache hits. |
0
|
cache_misses
|
int
|
Number of cache misses. |
0
|
Returns:
| Type | Description |
|---|---|
LintSummary
|
A LintSummary with counts derived from the diagnostics. |
Source code in behave_lint/models/lint_result.py
PerformanceImpact
¶
Bases: Enum
Execution cost of a rule.
Members
NEGLIGIBLE: Near-zero cost (simple checks). LOW: Fast (single-pass, no I/O). MEDIUM: Moderate (multi-pass or cross-file). HIGH: Expensive (may require step definition analysis).
Source code in behave_lint/models/enums.py
RuleExample
dataclass
¶
A before/after example for a rule.
Attributes:
| Name | Type | Description |
|---|---|---|
before |
str
|
Gherkin code that triggers the rule. |
after |
str
|
Gherkin code after the fix, or "No fix available". |
description |
str
|
Explanation of the example. |
Source code in behave_lint/models/rule_metadata.py
RuleMetadata
dataclass
¶
Identity and documentation for a rule.
Attributes:
| Name | Type | Description |
|---|---|---|
rule_id |
str
|
Stable, unique identifier (e.g., "BC001"). |
name |
str
|
Short, human-readable, kebab-case name. |
title |
str
|
One-line summary for CLI and documentation. |
description |
str
|
One-paragraph description of what the rule checks. |
category |
Category
|
Rule category. |
default_severity |
Severity
|
Default severity when the rule is enabled. |
motivation |
str
|
Why the rule exists — the problem it solves. |
since |
str
|
Version when the rule was introduced. |
examples |
list[RuleExample]
|
Before/after examples for documentation. |
auto_fix |
AutoFixCapability
|
Auto-fix capability. Defaults to NONE. |
tags |
list[str]
|
Free-form tags for filtering and grouping. |
references |
list[str]
|
External references (URLs, book sections, standards). |
configurable |
bool
|
Whether the rule accepts parameters. |
experimental |
bool
|
Whether the rule is experimental. |
deprecated |
bool
|
Whether the rule is deprecated. |
deprecated_version |
str | None
|
Version in which the rule was deprecated. |
replaced_by |
str | None
|
Rule ID that replaces this one, or None. |
aliases |
list[str]
|
Alternative names for backward compatibility. |
dependencies |
list[str]
|
Rule IDs that must execute before this rule. |
conflicts |
list[str]
|
Rule IDs that conflict with this rule. |
doc_url |
str | None
|
URL to rule documentation, or None. |
author |
str | None
|
Author or maintainer of the rule, or None. |
min_version |
str | None
|
Minimum behave-lint version required, or None. |
estimated_fix_cost |
FixCost
|
Estimated effort to fix. |
performance_impact |
PerformanceImpact
|
Execution cost. |
educational_value |
EducationalValue
|
Pedagogical value. |
Source code in behave_lint/models/rule_metadata.py
__post_init__()
¶
Validate field constraints after initialization.
Source code in behave_lint/models/rule_metadata.py
Severity
¶
Bases: Enum
Importance level of a diagnostic.
Members
ERROR: Must be fixed; causes non-zero exit code. WARNING: Should be fixed; does not cause non-zero exit by default. INFO: Informational; never affects exit code. OFF: Rule is disabled; no diagnostics are produced.
Source code in behave_lint/models/enums.py
from_string(value)
classmethod
¶
Parse a string into a Severity member.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Case-insensitive severity string. |
required |
Returns:
| Type | Description |
|---|---|
Severity
|
The matching Severity member. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string does not match any member. |
Source code in behave_lint/models/enums.py
load_config(*, config_path=None, overrides=None, env=None, start_dir=None)
¶
Load and resolve configuration from all sources.
Merges configuration from four sources by precedence: 1. Built-in defaults (lowest) 2. pyproject.toml [tool.behave-lint] 3. Environment variables (BEHAVE_LINT_*) 4. Explicit overrides (highest)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str | None
|
Explicit path to a pyproject.toml. If None, searches the current directory and ancestors. |
None
|
overrides
|
dict[str, object] | None
|
Dictionary of configuration overrides (same keys as Config fields). These have the highest precedence. |
None
|
env
|
dict[str, str] | None
|
Environment dict. If None, uses os.environ. |
None
|
start_dir
|
Path | None
|
Directory to start searching from. Defaults to cwd. |
None
|
Returns:
| Type | Description |
|---|---|
Config
|
A resolved Config object. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If configuration is invalid (unknown key, invalid value, invalid severity). |
Source code in behave_lint/configuration/loader.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |