Commit f5888bb7 authored by maruel@chromium.org's avatar maruel@chromium.org

Add CheckChangeHasNoStrayWhitespace().

TEST=unit tests
BUG=none

Review URL: http://codereview.chromium.org/118527

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18081 0039d316-1c4b-4281-b951-d872f2087c98
parent 0874d474
......@@ -144,6 +144,20 @@ def CheckChangeHasNoTabs(input_api, output_api, source_file_filter=None):
return []
def CheckChangeHasNoStrayWhitespace(input_api, output_api,
source_file_filter=None):
"""Checks that there is no stray whitespace at source lines end."""
errors = []
for f, line_num, line in input_api.RightHandSideLines(source_file_filter):
if line.rstrip() != line:
errors.append("%s, line %s" % (f.LocalPath(), line_num))
if errors:
return [output_api.PresubmitPromptWarning(
"Found line ending with white spaces in:",
long_text="\n".join(errors))]
return []
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.
......
......@@ -938,6 +938,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.mox.ReplayAll()
members = [
'CheckChangeHasBugField', 'CheckChangeHasDescription',
'CheckChangeHasNoStrayWhitespace',
'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR',
'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs',
'CheckChangeHasQaField', 'CheckChangeHasTestedField',
......@@ -1093,6 +1094,14 @@ class CannedChecksUnittest(PresubmitTestsBase):
'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT',
presubmit.OutputApi.PresubmitError)
def testCheckChangeHasNoStrayWhitespace(self):
self.ContentTest(
lambda x,y,z:
presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y),
'Foo', 'Foo ',
presubmit.OutputApi.PresubmitPromptWarning)
def testCheckChangeHasOnlyOneEol(self):
self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol,
"Hey!\nHo!\n", "Hey!\nHo!\n\n",
......
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