mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
presubmit: support checking new TODO format
R=sokcevic Bug: 1479023 Change-Id: I6eabb16447526fbc8de83b823763888aff1a8249 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4847314 Reviewed-by: Josip Sokcevic <sokcevic@chromium.org> Commit-Queue: Josip Sokcevic <sokcevic@chromium.org> Auto-Submit: Yiwei Zhang <yiwzhang@google.com>
This commit is contained in:
@@ -539,12 +539,16 @@ def CheckChangeHasNoTabs(input_api, output_api, source_file_filter=None):
|
||||
|
||||
|
||||
def CheckChangeTodoHasOwner(input_api, output_api, source_file_filter=None):
|
||||
"""Checks that the user didn't add TODO(name) without an owner."""
|
||||
|
||||
unowned_todo = input_api.re.compile('TO' 'DO[^(]')
|
||||
"""Checks that the user didn't add `TODO(name)` or `TODO: name -` without
|
||||
an owner.
|
||||
"""
|
||||
legacyTODO = '\\s*\\(.+\\)\\s*:'
|
||||
modernTODO = ':\\s*[^\\s]+\\s*\\-'
|
||||
unowned_todo = input_api.re.compile('TODO(?!(%s|%s))' %
|
||||
(legacyTODO, modernTODO))
|
||||
errors = _FindNewViolationsOfRule(lambda _, x: not unowned_todo.search(x),
|
||||
input_api, source_file_filter)
|
||||
errors = ['Found TO' 'DO with no owner in ' + x for x in errors]
|
||||
errors = ['Found TODO with no owner in ' + x for x in errors]
|
||||
if errors:
|
||||
return [output_api.PresubmitPromptWarning('\n'.join(errors))]
|
||||
return []
|
||||
|
||||
@@ -2049,6 +2049,9 @@ class CannedChecksUnittest(PresubmitTestsBase):
|
||||
presubmit.OutputApi.PresubmitPromptWarning)
|
||||
|
||||
def testCheckChangeTodoHasOwner(self):
|
||||
self.ContentTest(presubmit_canned_checks.CheckChangeTodoHasOwner,
|
||||
"TODO: foo - bar", None, "TODO: bar", None,
|
||||
presubmit.OutputApi.PresubmitPromptWarning)
|
||||
self.ContentTest(presubmit_canned_checks.CheckChangeTodoHasOwner,
|
||||
"TODO(foo): bar", None, "TODO: bar", None,
|
||||
presubmit.OutputApi.PresubmitPromptWarning)
|
||||
|
||||
Reference in New Issue
Block a user