Skip to content

Commit

Permalink
Add strict_typing rule to quality_scale hassfest validation (home-ass…
Browse files Browse the repository at this point in the history
…istant#131877)

* Add strict_typing rule to quality_scale hassfest validation

* Add acaia to .strict-typing
  • Loading branch information
epenet authored Nov 28, 2024
1 parent 8b46726 commit d596b41
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion script/hassfest/quality_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
diagnostics,
reauthentication_flow,
reconfiguration_flow,
strict_typing,
)

QUALITY_SCALE_TIERS = {value.name.lower(): value for value in ScaledQualityScaleTiers}
Expand Down Expand Up @@ -93,7 +94,7 @@ class Rule:
# 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 = {
Expand Down
35 changes: 35 additions & 0 deletions script/hassfest/quality_scale_validation/strict_typing.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d596b41

Please sign in to comment.