Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: PRESUBMIT.py

Issue 258473002: Add simple PRESUBMIT check to ensure that all files ending with .json can (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 67d55784370af84d31bed60125693639449c3d1f..e6c107765321fafd1ebf5e9d3d887a8bad2e08ab 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -9,6 +9,7 @@ for more details about the presubmit API built into gcl.
"""
+import json
M-A Ruel 2014/04/24 00:32:50 not needed
import re
import sys
@@ -1062,6 +1063,20 @@ def _CheckUserActionUpdate(input_api, output_api):
return []
+def _CheckJSONParsability(input_api, output_api):
+ results = []
+ file_filter = lambda f: f.LocalPath().endswith('.json')
+ for fpath in input_api.AffectedFiles(file_filter= file_filter):
M-A Ruel 2014/04/24 00:32:50 remove space
iannucci 2014/04/24 00:36:20 Oops, Done.
+ with open(fpath.LocalPath(), 'r') as f:
+ try:
+ json.load(f)
M-A Ruel 2014/04/24 00:32:50 input_api.json.load(f)
iannucci 2014/04/24 00:36:20 Done.
+ except ValueError:
+ results.append(output_api.PresubmitError(
+ "File %r does not parse as valid JSON" % (fpath.LocalPath())
+ ))
+ return results
+
+
def _CheckJavaStyle(input_api, output_api):
"""Runs checkstyle on changed java files and returns errors if any exist."""
original_sys_path = sys.path
@@ -1112,6 +1127,7 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckForAnonymousVariables(input_api, output_api))
results.extend(_CheckCygwinShell(input_api, output_api))
results.extend(_CheckUserActionUpdate(input_api, output_api))
+ results.extend(_CheckJSONParsability(input_api, output_api))
if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698