forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add strict_typing rule to quality_scale hassfest validation (home-ass…
…istant#131877) * Add strict_typing rule to quality_scale hassfest validation * Add acaia to .strict-typing
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |