[test] Add presubmit check that validates json files
NOTRY=true Change-Id: I74ba0860e33d954a864476a01bd829f0e91e527e Reviewed-on: https://chromium-review.googlesource.com/509533 Commit-Queue: Michael Achenbach <machenbach@chromium.org> Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#45462}
This commit is contained in:
parent
652c9522d3
commit
dfc4d3f3a4
21
PRESUBMIT.py
21
PRESUBMIT.py
@ -31,6 +31,7 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
|
||||
for more details about the presubmit API built into gcl.
|
||||
"""
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
@ -277,6 +278,7 @@ def _CommonChecks(input_api, output_api):
|
||||
results.extend(
|
||||
_CheckNoInlineHeaderIncludesInNormalHeaders(input_api, output_api))
|
||||
results.extend(_CheckMissingFiles(input_api, output_api))
|
||||
results.extend(_CheckJSONFiles(input_api, output_api))
|
||||
return results
|
||||
|
||||
|
||||
@ -316,6 +318,25 @@ def _CheckCommitMessageBugEntry(input_api, output_api):
|
||||
return [output_api.PresubmitError(r) for r in results]
|
||||
|
||||
|
||||
def _CheckJSONFiles(input_api, output_api):
|
||||
def FilterFile(affected_file):
|
||||
return input_api.FilterSourceFile(
|
||||
affected_file,
|
||||
white_list=(r'.+\.json',))
|
||||
|
||||
results = []
|
||||
for f in input_api.AffectedFiles(
|
||||
file_filter=FilterFile, include_deletes=False):
|
||||
with open(f.LocalPath()) as j:
|
||||
try:
|
||||
json.load(j)
|
||||
except Exception as e:
|
||||
results.append(
|
||||
'JSON validation failed for %s. Error:\n%s' % (f.LocalPath(), e))
|
||||
|
||||
return [output_api.PresubmitError(r) for r in results]
|
||||
|
||||
|
||||
def CheckChangeOnUpload(input_api, output_api):
|
||||
results = []
|
||||
results.extend(_CommonChecks(input_api, output_api))
|
||||
|
Loading…
Reference in New Issue
Block a user