From f5888bb793e8773afee2843a1a55d007b7fdd6af Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Wed, 10 Jun 2009 20:26:37 +0000 Subject: [PATCH] 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 --- presubmit_canned_checks.py | 14 ++++++++++++++ tests/presubmit_unittest.py | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index aad8b08691..dd3313196c 100755 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -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. diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 0f2ec1b577..cf21017bb6 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -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",