Add strict_typing rule to quality_scale hassfest validation (#131877)

* Add strict_typing rule to quality_scale hassfest validation

* Add acaia to .strict-typing
This commit is contained in:
epenet 2024-11-28 22:05:34 +01:00 committed by GitHub
parent 8b467268df
commit d596b4169d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 1 deletions

View File

@ -41,6 +41,7 @@ homeassistant.util.unit_system
# --- Add components below this line ---
homeassistant.components
homeassistant.components.abode.*
homeassistant.components.acaia.*
homeassistant.components.accuweather.*
homeassistant.components.acer_projector.*
homeassistant.components.acmeda.*

View File

@ -165,6 +165,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.acaia.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.accuweather.*]
check_untyped_defs = true
disallow_incomplete_defs = true

View File

@ -19,6 +19,7 @@ from .quality_scale_validation import (
diagnostics,
reauthentication_flow,
reconfiguration_flow,
strict_typing,
)
QUALITY_SCALE_TIERS = {value.name.lower(): value for value in ScaledQualityScaleTiers}
@ -93,7 +94,7 @@ ALL_RULES = [
# PLATINUM
Rule("async-dependency", ScaledQualityScaleTiers.PLATINUM),
Rule("inject-websession", ScaledQualityScaleTiers.PLATINUM),
Rule("strict-typing", ScaledQualityScaleTiers.PLATINUM),
Rule("strict-typing", ScaledQualityScaleTiers.PLATINUM, strict_typing),
]
SCALE_RULES = {

View File

@ -0,0 +1,35 @@
"""Enforce that the integration has strict typing enabled.
https://developers.home-assistant.io/docs/core/integration-quality-scale/rules/strict-typing/
"""
from functools import lru_cache
from pathlib import Path
import re
from script.hassfest.model import Integration
_STRICT_TYPING_FILE = Path(".strict-typing")
_COMPONENT_REGEX = r"homeassistant.components.([^.]+).*"
@lru_cache
def _strict_typing_components() -> set[str]:
return set(
{
match.group(1)
for line in _STRICT_TYPING_FILE.read_text(encoding="utf-8").splitlines()
if (match := re.match(_COMPONENT_REGEX, line)) is not None
}
)
def validate(integration: Integration) -> list[str] | None:
"""Validate that the integration has strict typing enabled."""
if integration.domain not in _strict_typing_components():
return [
"Integration does not have strict typing enabled "
"(is missing from .strict-typing)"
]
return None