From 3468e6aa77709110a0cc8ab4cd0230af78eae6ba Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 31 Oct 2024 15:45:44 +0100 Subject: [PATCH] Support excluding harness files from the unused includes check --- tools/lint/lib/checks/includes.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/lint/lib/checks/includes.py b/tools/lint/lib/checks/includes.py index 5ec38b5ce8..7c92d814ef 100644 --- a/tools/lint/lib/checks/includes.py +++ b/tools/lint/lib/checks/includes.py @@ -22,10 +22,14 @@ class CheckIncludes(Check): with open(os.path.join('harness', include_name), 'r') as f: source = f.read() + parsed = parse(source) + if not parsed: + raise Exception(f"Failed to parse {include_name}") CheckIncludes._cache[include_name] = { 'name': include_name, 'source': CheckIncludes._remove_frontmatter(source), - 'defines': parse(source)['defines'] + 'defines': parsed['defines'], + 'allow_unused': parsed.get('allow_unused', False), } return CheckIncludes._cache.get(include_name) @@ -57,6 +61,9 @@ class CheckIncludes(Check): without_frontmatter = self._remove_frontmatter(source) for harness_file in harness_files: + if harness_file['allow_unused']: + continue + if self._has_reference(without_frontmatter, harness_file['defines']): continue