OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Presubmit script for ui. | 5 """Presubmit script for ui. |
6 | 6 |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
8 for more details about the presubmit API built into depot_tools. | 8 for more details about the presubmit API built into depot_tools. |
9 """ | 9 """ |
10 | 10 |
11 INCLUDE_CPP_FILES_ONLY = ( | 11 INCLUDE_CPP_FILES_ONLY = ( |
12 r'.*\.(cc|h|mm)$', | 12 r'.*\.(cc|h|mm)$', |
13 ) | 13 ) |
14 | 14 |
15 | |
16 def CheckScopedPtr(input_api, output_api, | 15 def CheckScopedPtr(input_api, output_api, |
17 white_list=INCLUDE_CPP_FILES_ONLY, black_list=None): | 16 white_list=INCLUDE_CPP_FILES_ONLY, black_list=None): |
18 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 17 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
19 source_file_filter = lambda x: input_api.FilterSourceFile(x, | 18 source_file_filter = lambda x: input_api.FilterSourceFile(x, |
20 white_list, | 19 white_list, |
21 black_list) | 20 black_list) |
22 errors = [] | 21 errors = [] |
23 for f in input_api.AffectedSourceFiles(source_file_filter): | 22 for f in input_api.AffectedSourceFiles(source_file_filter): |
24 for line_number, line in f.ChangedContents(): | 23 for line_number, line in f.ChangedContents(): |
25 # Disallow: | 24 # Disallow: |
26 # return scoped_ptr<T>(foo); | 25 # scoped_ptr<T>() |
27 # bar = scoped_ptr<T>(foo); | 26 if input_api.re.search(r'\bscoped_ptr<.*?>\(\)', line): |
28 # But allow: | |
29 # return scoped_ptr<T[]>(foo); | |
30 # bar = scoped_ptr<T[]>(foo); | |
31 if input_api.re.search( | |
32 r'(=|\breturn)\s*scoped_ptr<[^\[\]>]+>\([^)]+\)', line): | |
33 errors.append(output_api.PresubmitError( | 27 errors.append(output_api.PresubmitError( |
34 ('%s:%d uses explicit scoped_ptr constructor. ' + | 28 '%s:%d uses scoped_ptr<T>(). Use nullptr instead.' % |
35 'Use make_scoped_ptr() instead.') % (f.LocalPath(), line_number))) | 29 (f.LocalPath(), line_number))) |
36 # Disallow: | |
37 # scoped_ptr<T>() | |
38 if re.search(r'\bscoped_ptr<.*?>\(\)', line): | |
39 errors.append(output_api.PresubmitError( | |
40 '%s:%d uses scoped_ptr<T>(). Use nullptr instead.' % | |
41 (f.LocalPath(), line_number))) | |
42 return errors | 30 return errors |
43 | 31 |
44 | 32 |
45 def CheckChange(input_api, output_api): | 33 def CheckChange(input_api, output_api): |
46 results = [] | 34 results = [] |
47 results += CheckScopedPtr(input_api, output_api) | 35 results += CheckScopedPtr(input_api, output_api) |
48 return results | 36 return results |
49 | 37 |
50 | 38 |
51 def CheckChangeOnUpload(input_api, output_api): | 39 def CheckChangeOnUpload(input_api, output_api): |
52 return CheckChange(input_api, output_api) | 40 return CheckChange(input_api, output_api) |
53 | 41 |
54 | 42 |
55 def CheckChangeOnCommit(input_api, output_api): | 43 def CheckChangeOnCommit(input_api, output_api): |
56 return CheckChange(input_api, output_api) | 44 return CheckChange(input_api, output_api) |
OLD | NEW |