Commit dfc4d3f3 authored by Michael Achenbach's avatar Michael Achenbach Committed by Commit Bot

[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: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45462}
parent 652c9522
...@@ -31,6 +31,7 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts ...@@ -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. for more details about the presubmit API built into gcl.
""" """
import json
import re import re
import sys import sys
...@@ -277,6 +278,7 @@ def _CommonChecks(input_api, output_api): ...@@ -277,6 +278,7 @@ def _CommonChecks(input_api, output_api):
results.extend( results.extend(
_CheckNoInlineHeaderIncludesInNormalHeaders(input_api, output_api)) _CheckNoInlineHeaderIncludesInNormalHeaders(input_api, output_api))
results.extend(_CheckMissingFiles(input_api, output_api)) results.extend(_CheckMissingFiles(input_api, output_api))
results.extend(_CheckJSONFiles(input_api, output_api))
return results return results
...@@ -316,6 +318,25 @@ def _CheckCommitMessageBugEntry(input_api, output_api): ...@@ -316,6 +318,25 @@ def _CheckCommitMessageBugEntry(input_api, output_api):
return [output_api.PresubmitError(r) for r in results] 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): def CheckChangeOnUpload(input_api, output_api):
results = [] results = []
results.extend(_CommonChecks(input_api, output_api)) results.extend(_CommonChecks(input_api, output_api))
......
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