diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 9976f289d82033..d795226df304c0 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -6829,7 +6829,7 @@ def FileFilter(affected_file): output_api.PresubmitError( 'Please add assert(is_chromeos_ash) to %s. If that\'s not ' 'possible, please create and issue and add a comment such ' - 'as:\n # TODO(https://crbug.com/XXX): add ' + 'as:\n # TODO(crbug.com/XXX): add ' 'assert(is_chromeos_ash) when ...' % f.LocalPath())) return errors @@ -6855,7 +6855,7 @@ def _IsMiraclePtrDisallowed(input_api, affected_file): # We assume that everything else may be used outside of Renderer processes. return False -# TODO(https://crbug.com/1273182): Remove these checks, once they are replaced +# TODO(crbug.com/40206238): Remove these checks, once they are replaced # by the Chromium Clang Plugin (which will be preferable because it will # 1) report errors earlier - at compile-time and 2) cover more rules). def CheckRawPtrUsage(input_api, output_api): @@ -7298,3 +7298,34 @@ def CheckInlineConstexprDefinitionsInHeaders(input_api, output_api): ] else: return [] + +def CheckTodoBugReferences(input_api, output_api): + """Checks that bugs in TODOs use updated issue tracker IDs.""" + + files_to_skip = ['PRESUBMIT_test.py'] + + def _FilterFile(affected_file): + return input_api.FilterSourceFile( + affected_file, + files_to_skip=files_to_skip) + + # Monorail bug IDs are all less than or equal to 1524553 so check that all + # bugs in TODOs are greater than that value. + pattern = input_api.re.compile(r'.*TODO\([^\)0-9]*([0-9]+)\).*') + problems = [] + for f in input_api.AffectedSourceFiles(_FilterFile): + for line_number, line in f.ChangedContents(): + match = pattern.match(line) + if match and int(match.group(1)) <= 1524553: + problems.append( + f"{f.LocalPath()}: {line_number}\n {line}") + + if problems: + return [ + output_api.PresubmitPromptWarning( + 'TODOs should use the new Chromium Issue Tracker IDs. ' + 'See https://crbug.com/321899722 for more details.', + problems) + ] + else: + return [] diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index 638e942e20acbe..707d3eee4cae9a 100755 --- a/PRESUBMIT_test.py +++ b/PRESUBMIT_test.py @@ -5310,5 +5310,23 @@ def testNoExplicitInlineConstexprInsideClassInHeaderFile(self): warnings = PRESUBMIT.CheckInlineConstexprDefinitionsInHeaders(input_api, MockOutputApi()) self.assertEqual(0, len(warnings)) + def testTodoBugReferencesWithOldBugId(self): + """Tests that an old monorail bug ID in a TODO fails.""" + input_api = MockInputApi() + input_api.files = [ + MockAffectedFile('src/helpers.h', ['// TODO(crbug.com/12345)']) + ] + warnings = PRESUBMIT.CheckTodoBugReferences(input_api, MockOutputApi()) + self.assertEqual(1, len(warnings)) + + def testTodoBugReferencesWithUpdatedBugId(self): + """Tests that a new issue tracker bug ID in a TODO passes.""" + input_api = MockInputApi() + input_api.files = [ + MockAffectedFile('src/helpers.h', ['// TODO(crbug.com/40781525)']) + ] + warnings = PRESUBMIT.CheckTodoBugReferences(input_api, MockOutputApi()) + self.assertEqual(0, len(warnings)) + if __name__ == '__main__': unittest.main()