Reduce _CheckUniquePtr spam
Currently, _CheckUniquePtr PRESUBMIT check reports each failing line as
a separate error. This repeats the error explanation and thus clutters
the output necessarily.
This CL makes _CheckUniquePtr collect all occurences of the two issues
it checks for (direct use of unique_ptr constructor and replaceability
with nullptr) and group them under a separate single error, one for each
of the both types of check.
It also adds the failing line into the output, to make it easier to
understand the issue already from the presubmit logs.
This follows what is done for other checks, e.g., _CheckNoPragmaOnce).
Bug: 827961
Change-Id: Ic7d60a05b6f96da741f1401422f4a1690bb6e279
Reviewed-on: https://chromium-review.googlesource.com/990132
Commit-Queue: Vaclav Brozek <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Cr-Commit-Position: refs/heads/master@{#548081}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index b54a8875..da27147 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1589,7 +1589,8 @@
r'(=|\breturn|^)\s*std::unique_ptr<.*?(?<!])>\(([^)]|$)')
null_construct_pattern = input_api.re.compile(
r'\b(?<!<)std::unique_ptr<[^>]*>([^(<]*>)?\(\)')
- errors = []
+ problems_constructor = []
+ problems_nullptr = []
for f in input_api.AffectedSourceFiles(sources):
for line_number, line in f.ChangedContents():
# Disallow:
@@ -1598,17 +1599,26 @@
# But allow:
# return std::unique_ptr<T[]>(foo);
# bar = std::unique_ptr<T[]>(foo);
+ local_path = f.LocalPath()
if return_construct_pattern.search(line):
- errors.append(output_api.PresubmitError(
- ('%s:%d uses explicit std::unique_ptr constructor. ' +
- 'Use std::make_unique<T>() instead.') %
- (f.LocalPath(), line_number)))
+ problems_constructor.append(
+ '%s:%d\n %s' % (local_path, line_number, line.strip()))
# Disallow:
# std::unique_ptr<T>()
if null_construct_pattern.search(line):
- errors.append(output_api.PresubmitError(
- '%s:%d uses std::unique_ptr<T>(). Use nullptr instead.' %
- (f.LocalPath(), line_number)))
+ problems_nullptr.append(
+ '%s:%d\n %s' % (local_path, line_number, line.strip()))
+
+ errors = []
+ if problems_constructor:
+ errors.append(output_api.PresubmitError(
+ 'The following files use std::unique_ptr<T>(). Use nullptr instead.',
+ problems_constructor))
+ if problems_nullptr:
+ errors.append(output_api.PresubmitError(
+ 'The following files use explicit std::unique_ptr constructor.'
+ 'Use std::make_unique<T>() instead.',
+ problems_nullptr))
return errors