Chromium Code Reviews| Index: PRESUBMIT.py |
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
| index 7388cf8b61307a043e8f06ccdf3e164e357f0002..7a9c6fd98e1c11c757e0f221ee8139b4c69ce199 100755 |
| --- a/PRESUBMIT.py |
| +++ b/PRESUBMIT.py |
| @@ -339,6 +339,42 @@ def _CheckUnwantedDependencies(input_api, output_api): |
| return results |
| +def _GetJSONParseError(input_api, filename): |
| + try: |
| + contents = input_api.ReadFile(filename) |
| + input_api.json.loads(contents) |
| + except ValueError as e: |
| + return e |
| + return None |
| + |
| + |
| +def _CheckJSONParseErrors(input_api, output_api): |
| + """Check that JSON files do not contain syntax errors.""" |
| + actions = { |
|
phoglund
2016/02/11 08:38:56
Is this a pattern generally followed by all presub
kjellander_webrtc
2016/02/11 09:24:15
Chromium has IDL files as well (https://code.googl
|
| + '.json': _GetJSONParseError, |
| + } |
| + |
| + def get_action(affected_file): |
| + filename = affected_file.LocalPath() |
| + return actions.get(input_api.os_path.splitext(filename)[1]) |
| + |
| + def FilterFile(affected_file): |
| + action = get_action(affected_file) |
| + if not action: |
| + return False |
| + return True |
| + |
| + results = [] |
| + for affected_file in input_api.AffectedFiles( |
| + file_filter=FilterFile, include_deletes=False): |
| + action = get_action(affected_file) |
| + parse_error = action(input_api, affected_file.AbsoluteLocalPath()) |
| + if parse_error: |
| + results.append(output_api.PresubmitError('%s could not be parsed: %s' % |
| + (affected_file.LocalPath(), parse_error))) |
| + return results |
| + |
| + |
| def _RunPythonTests(input_api, output_api): |
| def join(*args): |
| return input_api.os_path.join(input_api.PresubmitLocalPath(), *args) |
| @@ -423,6 +459,7 @@ def _CommonChecks(input_api, output_api): |
| results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) |
| results.extend(_CheckGypChanges(input_api, output_api)) |
| results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
| + results.extend(_CheckJSONParseErrors(input_api, output_api)) |
| results.extend(_RunPythonTests(input_api, output_api)) |
| return results |