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 <ehmaldonado@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
changes/35/2992735/2
Josip Sokcevic 4 years ago committed by LUCI CQ
parent 866be0f290
commit f0d7ed89cf

@ -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:

Loading…
Cancel
Save