mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
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:
parent
8b467268df
commit
d596b4169d
@ -41,6 +41,7 @@ homeassistant.util.unit_system
|
|||||||
# --- Add components below this line ---
|
# --- Add components below this line ---
|
||||||
homeassistant.components
|
homeassistant.components
|
||||||
homeassistant.components.abode.*
|
homeassistant.components.abode.*
|
||||||
|
homeassistant.components.acaia.*
|
||||||
homeassistant.components.accuweather.*
|
homeassistant.components.accuweather.*
|
||||||
homeassistant.components.acer_projector.*
|
homeassistant.components.acer_projector.*
|
||||||
homeassistant.components.acmeda.*
|
homeassistant.components.acmeda.*
|
||||||
|
10
mypy.ini
10
mypy.ini
@ -165,6 +165,16 @@ disallow_untyped_defs = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = 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.*]
|
[mypy-homeassistant.components.accuweather.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
@ -19,6 +19,7 @@ from .quality_scale_validation import (
|
|||||||
diagnostics,
|
diagnostics,
|
||||||
reauthentication_flow,
|
reauthentication_flow,
|
||||||
reconfiguration_flow,
|
reconfiguration_flow,
|
||||||
|
strict_typing,
|
||||||
)
|
)
|
||||||
|
|
||||||
QUALITY_SCALE_TIERS = {value.name.lower(): value for value in ScaledQualityScaleTiers}
|
QUALITY_SCALE_TIERS = {value.name.lower(): value for value in ScaledQualityScaleTiers}
|
||||||
@ -93,7 +94,7 @@ ALL_RULES = [
|
|||||||
# PLATINUM
|
# PLATINUM
|
||||||
Rule("async-dependency", ScaledQualityScaleTiers.PLATINUM),
|
Rule("async-dependency", ScaledQualityScaleTiers.PLATINUM),
|
||||||
Rule("inject-websession", ScaledQualityScaleTiers.PLATINUM),
|
Rule("inject-websession", ScaledQualityScaleTiers.PLATINUM),
|
||||||
Rule("strict-typing", ScaledQualityScaleTiers.PLATINUM),
|
Rule("strict-typing", ScaledQualityScaleTiers.PLATINUM, strict_typing),
|
||||||
]
|
]
|
||||||
|
|
||||||
SCALE_RULES = {
|
SCALE_RULES = {
|
||||||
|
35
script/hassfest/quality_scale_validation/strict_typing.py
Normal file
35
script/hassfest/quality_scale_validation/strict_typing.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user