From f0d7ed89cf004297a21b53bcbbffc4f7dc21b6ed Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Wed, 30 Jun 2021 18:35:46 +0000 Subject: [PATCH] Allow custom filters for json validation JSON check may be useful for files that don't necessaraly end with .json. For example, infra/config/recipes.cfg should be a json file. This change allows users to add custom file_filter that can include such files. R=apolito@google.com Bug: 1223923 Change-Id: Ia6fc7f86fa368510baaee978d9a0a27eccb6b31f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2992735 Reviewed-by: Edward Lesmes Commit-Queue: Josip Sokcevic --- presubmit_canned_checks.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 40e91efdf6..a14c9202bb 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1736,12 +1736,15 @@ def CheckLucicfgGenOutput(input_api, output_api, entry_script): output_api.PresubmitError) ] -def CheckJsonParses(input_api, output_api): - """Verifies that all JSON files at least parse as valid JSON.""" +def CheckJsonParses(input_api, output_api, file_filter=None): + """Verifies that all JSON files at least parse as valid JSON. By default, + file_filter will look for all files that end with .json""" import json + if file_filter is None: + file_filter = lambda x: x.LocalPath().endswith('.json') affected_files = input_api.AffectedFiles( include_deletes=False, - file_filter=lambda x: x.LocalPath().endswith('.json')) + file_filter=file_filter) warnings = [] for f in affected_files: with open(f.AbsoluteLocalPath()) as j: