Chromium Code Reviews| Index: cc/PRESUBMIT.py |
| diff --git a/cc/PRESUBMIT.py b/cc/PRESUBMIT.py |
| index 6c08441f405eea1d402681b81e62660a17457b28..6ec8085208c5dc952f8b5b3f8204f31f763cb29e 100644 |
| --- a/cc/PRESUBMIT.py |
| +++ b/cc/PRESUBMIT.py |
| @@ -146,6 +146,34 @@ def CheckTodos(input_api, output_api): |
| items=errors)] |
| return [] |
| +def CheckScopedPtr(input_api, output_api, |
| + white_list=CC_SOURCE_FILES, black_list=None): |
| + black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
| + source_file_filter = lambda x: input_api.FilterSourceFile(x, |
| + white_list, |
| + black_list) |
| + errors = [] |
| + for f in input_api.AffectedSourceFiles(source_file_filter): |
| + for line_number, line in f.ChangedContents(): |
| + # Disallow: |
| + # return scoped_ptr<T>(foo); |
| + # bar = scoped_ptr<T>(foo); |
| + # But allow: |
| + # return scoped_ptr<T[]>(foo); |
| + # bar = scoped_ptr<T[]>(foo); |
| + if re.search(r'(=|\breturn)\s*scoped_ptr<[^>]*[^>\]]>\([^)]+\)', line): |
|
enne (OOO)
2014/09/26 16:58:22
regex nits:
matching non-greedily, [^>]*> is clea
|
| + errors.append(output_api.PresubmitError( |
| + ('%s:%d uses explicit scoped_ptr constructor. ' + |
| + 'Use make_scoped_ptr() instead.') % (f.LocalPath(), line_number))) |
| + # Disallow: |
| + # return scoped_ptr<T>(); |
| + # bar = scoped_ptr<T>(); |
| + if re.search(r'(=|\breturn)\s*scoped_ptr<[^>+]>\(\)', line): |
|
vmpstr
2014/09/26 16:44:23
... [^>]+ ...
?
danakj
2014/09/26 16:56:44
That matches the T in scoped_ptr<T>
It doesn't ha
enne (OOO)
2014/09/26 16:58:22
I think this is wrong; did you intend for the + to
|
| + errors.append(output_api.PresubmitError( |
| + '%s:%d uses scoped_ptr<T>(). Use nullptr instead.' % |
| + (f.LocalPath(), line_number))) |
| + return errors |
| + |
| def FindUnquotedQuote(contents, pos): |
| match = re.search(r"(?<!\\)(?P<quote>\")", contents[pos:]) |
| return -1 if not match else match.start("quote") + pos |
| @@ -286,6 +314,7 @@ def CheckChangeOnUpload(input_api, output_api): |
| results += CheckPassByValue(input_api, output_api) |
| results += CheckChangeLintsClean(input_api, output_api) |
| results += CheckTodos(input_api, output_api) |
| + results += CheckScopedPtr(input_api, output_api) |
| results += CheckNamespace(input_api, output_api) |
| results += CheckForUseOfWrongClock(input_api, output_api) |
| results += FindUselessIfdefs(input_api, output_api) |