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

Unified Diff: presubmit_canned_checks.py

Issue 119365: Add InputApi.AffectedSourceFile() and custom filtering support. (Closed)
Patch Set: comment Created 11 years, 6 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 | presubmit_support.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_canned_checks.py
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py
index 14c5a1b37f8e00f2ff8f94c14f46d68330b470ab..f31b1687a352e306dd1bd415d31e702a44c416e2 100755
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -6,6 +6,8 @@
"""Generic presubmit checks that can be reused by other presubmit checks."""
+### Description checks
+
def CheckChangeHasTestField(input_api, output_api):
"""Requires that the changelist have a TEST= field."""
if input_api.change.TEST:
@@ -51,40 +53,36 @@ def CheckDoNotSubmitInDescription(input_api, output_api):
return []
+### Content checks
+
def CheckDoNotSubmitInFiles(input_api, output_api):
"""Checks that the user didn't add 'DO NOT ' + 'SUBMIT' to any files."""
keyword = 'DO NOT ' + 'SUBMIT'
- for f, line_num, line in input_api.RightHandSideLines():
+ # We want to check every text files, not just source files.
+ for f, line_num, line in input_api.RightHandSideLines(lambda x: x):
if keyword in line:
text = 'Found ' + keyword + ' in %s, line %s' % (f.LocalPath(), line_num)
return [output_api.PresubmitError(text)]
return []
-def CheckDoNotSubmit(input_api, output_api):
- return (
- CheckDoNotSubmitInDescription(input_api, output_api) +
- CheckDoNotSubmitInFiles(input_api, output_api)
- )
-
-
-def CheckChangeHasNoCR(input_api, output_api):
+def CheckChangeHasNoCR(input_api, output_api, source_file_filter=None):
"""Checks that there are no \r, \r\n (CR or CRLF) characters in any of the
- text files to be submitted.
+ source files to be submitted.
"""
outputs = []
- for f in input_api.AffectedTextFiles():
+ for f in input_api.AffectedSourceFiles(source_file_filter):
if '\r' in input_api.ReadFile(f, 'rb'):
outputs.append(output_api.PresubmitPromptWarning(
"Found a CR character in %s" % f.LocalPath()))
return outputs
-def CheckChangeHasNoTabs(input_api, output_api):
+def CheckChangeHasNoTabs(input_api, output_api, source_file_filter=None):
"""Checks that there are no tab characters in any of the text files to be
submitted.
"""
- for f, line_num, line in input_api.RightHandSideLines():
+ for f, line_num, line in input_api.RightHandSideLines(source_file_filter):
if '\t' in line:
return [output_api.PresubmitPromptWarning(
"Found a tab character in %s, line %s" %
@@ -92,12 +90,12 @@ def CheckChangeHasNoTabs(input_api, output_api):
return []
-def CheckLongLines(input_api, output_api, maxlen=80):
+def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None):
"""Checks that there aren't any lines longer than maxlen characters in any of
the text files to be submitted.
"""
bad = []
- for f, line_num, line in input_api.RightHandSideLines():
+ for f, line_num, line in input_api.RightHandSideLines(source_file_filter):
# Allow lines with http://, https:// and #define/#pragma/#include/#if/#endif
# to exceed the maxlen rule.
if (len(line) > maxlen and
@@ -121,6 +119,15 @@ def CheckLongLines(input_api, output_api, maxlen=80):
return []
+### Other checks
+
+def CheckDoNotSubmit(input_api, output_api):
+ return (
+ CheckDoNotSubmitInDescription(input_api, output_api) +
+ CheckDoNotSubmitInFiles(input_api, output_api)
+ )
+
+
def CheckTreeIsOpen(input_api, output_api, url, closed):
"""Checks that an url's content doesn't match a regexp that would mean that
the tree is closed."""
@@ -145,6 +152,7 @@ def _RunPythonUnitTests_LoadTests(input_api, module_name):
module = getattr(module, part)
return input_api.unittest.TestLoader().loadTestsFromModule(module)._tests
+
def RunPythonUnitTests(input_api, output_api, unit_tests):
"""Imports the unit_tests modules and run them."""
# We don't want to hinder users from uploading incomplete patches.
« no previous file with comments | « no previous file | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698