Commit f0d7ed89 authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

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/+/2992735Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
parent 866be0f2
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment