diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 0fe2e174e4da4f..c2a4c5c3e0a0a8 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -1229,94 +1229,6 @@ def _CheckNoDeprecatedCSS(input_api, output_api): (fpath.LocalPath(), line_num, deprecated_value, value))) return results - -def _StripCommentsAndStrings(input_api, s): - """Remove comments, replace string literals by a single token. Requires that - input data is formatted with unix-style line ends.""" - - s = input_api.re.sub(r'\\\n', r'', s) # Continue lines ending in backslash. - - out = '' - i = 0 - while i < len(s): - c = s[i] - - if c == '/': - mo = input_api.re.match(r'//.*', s[i:]) - if mo: - i += len(mo.group(0)) - continue - mo = input_api.re.match(r'/\*.*?\*/', s[i:], input_api.re.DOTALL) - if mo: - i += len(mo.group(0)) - continue - - if c == "'": - mo = input_api.re.match(r"'((\\\\)|(\\')|[^']+?)'", s[i:]) - if not mo: - raise Exception('bad char: ' + s[i:]) - i += len(mo.group(0)) - out += ' CHAR_LITERAL ' - continue - - if c == '"': - mo = input_api.re.match(r'".*?(?.*?)((\bbreak\b)|})', - text, input_api.re.DOTALL) - # TODO(tnagel): Catch loops inside which NOTREACHED() is followed by break. - if not mo: - break - text = text[mo.end():] - if input_api.re.match(r'[\s;]*$', mo.group('between'), input_api.re.DOTALL): - continue - excerpt = mo.group(0).rstrip() - if len(excerpt) > 100: - excerpt = excerpt[:100] + ' \u2026' # ellipsis - results.append( - '%s: NOTREACHED() may only be used at end-of-block ' - 'but is followed by code.\n%s\n' - 'Offending section (comments/strings possibly stripped):\n%s' - % (f, style_url, excerpt)) - return results - - def _CommonChecks(input_api, output_api): """Checks common to both upload and commit.""" results = [] @@ -1354,7 +1266,6 @@ def _CommonChecks(input_api, output_api): results.extend(_CheckUserActionUpdate(input_api, output_api)) results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) results.extend(_CheckParseErrors(input_api, output_api)) - results.extend(_CheckContradictoryNotreachedUse(input_api, output_api)) if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): results.extend(input_api.canned_checks.RunUnitTestsInDirectory( diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index 760d70bfbf7318..f81b316aa2e025 100755 --- a/PRESUBMIT_test.py +++ b/PRESUBMIT_test.py @@ -413,52 +413,6 @@ def testValidOSMacroNames(self): self.assertEqual(0, len(errors)) -class CheckContradictoryNotreachedUseTest(unittest.TestCase): - def testValid(self): - lines = ['{', - ' // NOTREACHED();', - ' /* NOTREACHED(); */', - " char a = '\\\\', b = '\\0', c = '\\'';", - ' char d[] = "NOTREACHED();";', - ' NOTREACHED(); // blah', - ' /* comment */', - ' // line continuation \\', - ' still inside comment', - ' // comment followed by empty line', - '', - ' ;; ; ;;;', - '}', - 'switch (i) {', - ' case 7: NOTREACHED(); break;', - '}'] - output = PRESUBMIT._CheckContradictoryNotreachedUseInFile( - MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) - self.assertEqual(0, len(output)) - - def testInvalid(self): - lines = ['{', - ' NOTREACHED();', - ' return;', - '}', - '{', - ' NOTREACHED();', - ' /* */', - ' return;', - ' /* */', - '}', - '{', - ' NOTREACHED();', - ' // trailing space, not a line continuation \\ ', - ' return;', - '}', - 'switch (i) {', - ' case 7: NOTREACHED(); some_thing(); break;', - '}'] - output = PRESUBMIT._CheckContradictoryNotreachedUseInFile( - MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) - self.assertEqual(4, len(output)) - - class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase): def testFilesToCheckForIncomingDeps(self): changed_lines = [