From ca08b70984a3076f74326e05cb00c5417be6b463 Mon Sep 17 00:00:00 2001 From: Franck Nijhof <git@frenck.dev> Date: Tue, 21 Apr 2020 23:42:04 +0200 Subject: [PATCH] Revert removal of JSON validator in hassfest (#34504) Co-Authored-By: Paulus Schoutsen <balloob@gmail.com> --- script/hassfest/__main__.py | 2 ++ script/hassfest/json.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 script/hassfest/json.py diff --git a/script/hassfest/__main__.py b/script/hassfest/__main__.py index aec1fd34b15..6fbefc11a2f 100644 --- a/script/hassfest/__main__.py +++ b/script/hassfest/__main__.py @@ -9,6 +9,7 @@ from . import ( config_flow, coverage, dependencies, + json, manifest, services, ssdp, @@ -18,6 +19,7 @@ from . import ( from .model import Config, Integration INTEGRATION_PLUGINS = [ + json, codeowners, config_flow, dependencies, diff --git a/script/hassfest/json.py b/script/hassfest/json.py new file mode 100644 index 00000000000..39c1f6f13a9 --- /dev/null +++ b/script/hassfest/json.py @@ -0,0 +1,32 @@ +"""Validate integration JSON files.""" +import json +from typing import Dict + +from .model import Integration + + +def validate_json_files(integration: Integration): + """Validate JSON files for integration.""" + for json_file in integration.path.glob("**/*.json"): + if not json_file.is_file(): + continue + + try: + json.loads(json_file.read_text()) + except json.JSONDecodeError: + relative_path = json_file.relative_to(integration.path) + integration.add_error("json", f"Invalid JSON file {relative_path}") + + return + + +def validate(integrations: Dict[str, Integration], config): + """Handle JSON files inside integrations.""" + if not config.specific_integrations: + return + + for integration in integrations.values(): + if not integration.manifest: + continue + + validate_json_files(integration) -- GitLab