validation
ruff_sync.validation ¶
Validation logic for ruff-sync merged configurations.
__all__
module-attribute
¶
check_python_version_consistency ¶
Warn if the merged ruff target-version conflicts with requires-python.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
TOMLDocument
|
The merged TOML document (pyproject.toml format). |
required |
strict
|
bool
|
If True, treat version mismatch as a failure. |
False
|
exclude
|
Iterable[str]
|
List of keys excluded from the ruff configuration. |
()
|
Returns:
| Type | Description |
|---|---|
bool
|
True if versions are consistent or if check is skipped. |
bool
|
False if strict=True and versions are inconsistent. |
Source code in src/ruff_sync/validation.py
check_deprecated_rules ¶
check_deprecated_rules(
doc,
is_ruff_toml=False,
strict=False,
_deprecated_codes=None,
exclude=(),
)
Warn if the merged config references any deprecated Ruff rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
TOMLDocument
|
The merged TOML document. |
required |
is_ruff_toml
|
bool
|
True if the document is a standalone ruff.toml. |
False
|
strict
|
bool
|
If True, treat deprecated rules as a failure. |
False
|
_deprecated_codes
|
frozenset[str] | None
|
Optional set of deprecated codes to use (for testing). |
None
|
exclude
|
Iterable[str]
|
List of keys excluded from the ruff configuration. |
()
|
Returns:
| Type | Description |
|---|---|
bool
|
True if no deprecated rules are found, or if strict=False. |
bool
|
False if strict=True and deprecated rules are found. |
Source code in src/ruff_sync/validation.py
validate_toml_syntax ¶
Return True if the document serializes to valid TOML.
tomlkit always produces valid TOML, so this catches any edge cases where serialization itself raises an unexpected exception.
Source code in src/ruff_sync/validation.py
validate_ruff_accepts_config ¶
Return True if Ruff accepts the merged configuration.
Writes the merged config to a temporary file and runs
ruff check --isolated --config
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
TOMLDocument
|
The merged TOML document to validate. |
required |
is_ruff_toml
|
bool
|
True if the document is a ruff.toml (not pyproject.toml). |
False
|
strict
|
bool
|
If True, treat configuration warnings (deprecated rules, etc.) as failures. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if Ruff accepts the config without errors, False otherwise. |
Source code in src/ruff_sync/validation.py
validate_merged_config ¶
Run all validation checks on the merged TOML document.
Returns True only if all checks pass. Returns False and logs errors if any check fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
TOMLDocument
|
The merged TOML document to validate. |
required |
is_ruff_toml
|
bool
|
True if the document is a standalone ruff.toml. |
False
|
strict
|
bool
|
If True, treat configuration warnings as hard failures. |
False
|
exclude
|
Iterable[str]
|
List of keys excluded from the ruff configuration. |
()
|
Returns:
| Type | Description |
|---|---|
bool
|
True if all validation checks pass, False otherwise. |