OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" |
6 | 6 |
7 import os as _os | 7 import os as _os |
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) | 8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) |
9 | 9 |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 if text: | 88 if text: |
89 return [output_api.PresubmitError(text)] | 89 return [output_api.PresubmitError(text)] |
90 return [] | 90 return [] |
91 | 91 |
92 | 92 |
93 def CheckChangeLintsClean(input_api, output_api, source_file_filter=None): | 93 def CheckChangeLintsClean(input_api, output_api, source_file_filter=None): |
94 """Checks that all '.cc' and '.h' files pass cpplint.py.""" | 94 """Checks that all '.cc' and '.h' files pass cpplint.py.""" |
95 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') | 95 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') |
96 result = [] | 96 result = [] |
97 | 97 |
98 # Initialize cpplint. | 98 cpplint = input_api.cpplint |
99 import cpplint | |
100 # Access to a protected member _XX of a client class | 99 # Access to a protected member _XX of a client class |
101 # pylint: disable=W0212 | 100 # pylint: disable=W0212 |
102 cpplint._cpplint_state.ResetErrorCounts() | 101 cpplint._cpplint_state.ResetErrorCounts() |
103 | 102 |
104 # Justifications for each filter: | 103 # Justifications for each filter: |
105 # | 104 # |
106 # - build/include : Too many; fix in the future. | 105 # - build/include : Too many; fix in the future. |
107 # - build/include_order : Not happening; #ifdefed includes. | 106 # - build/include_order : Not happening; #ifdefed includes. |
108 # - build/namespace : I'm surprised by how often we violate this rule. | 107 # - build/namespace : I'm surprised by how often we violate this rule. |
109 # - readability/casting : Mistakes a whole bunch of function pointer. | 108 # - readability/casting : Mistakes a whole bunch of function pointer. |
110 # - runtime/int : Can be fixed long term; volume of errors too high | 109 # - runtime/int : Can be fixed long term; volume of errors too high |
111 # - runtime/virtual : Broken now, but can be fixed in the future? | 110 # - runtime/virtual : Broken now, but can be fixed in the future? |
112 # - whitespace/braces : We have a lot of explicit scoping in chrome code. | 111 # - whitespace/braces : We have a lot of explicit scoping in chrome code. |
113 cpplint._SetFilters('-build/include,-build/include_order,-build/namespace,' | 112 cpplint._SetFilters('-build/include,-build/include_order,-build/namespace,' |
114 '-readability/casting,-runtime/int,-runtime/virtual,' | 113 '-readability/casting,-runtime/int,-runtime/virtual,' |
115 '-whitespace/braces') | 114 '-whitespace/braces') |
116 | 115 |
117 # Replace <hash_map> and <hash_set> as headers that need to be included | |
118 # with "base/hash_tables.h" instead. | |
119 cpplint._re_pattern_templates = [ | |
120 (a, b, 'base/hash_tables.h') | |
121 if header in ('<hash_map>', '<hash_set>') else (a, b, header) | |
122 for (a, b, header) in cpplint._re_pattern_templates | |
123 ] | |
124 | |
125 # We currently are more strict with normal code than unit tests; 4 and 5 are | 116 # We currently are more strict with normal code than unit tests; 4 and 5 are |
126 # the verbosity level that would normally be passed to cpplint.py through | 117 # the verbosity level that would normally be passed to cpplint.py through |
127 # --verbose=#. Hopefully, in the future, we can be more verbose. | 118 # --verbose=#. Hopefully, in the future, we can be more verbose. |
128 files = [f.AbsoluteLocalPath() for f in | 119 files = [f.AbsoluteLocalPath() for f in |
129 input_api.AffectedSourceFiles(source_file_filter)] | 120 input_api.AffectedSourceFiles(source_file_filter)] |
130 for file_name in files: | 121 for file_name in files: |
131 if _RE_IS_TEST.match(file_name): | 122 if _RE_IS_TEST.match(file_name): |
132 level = 5 | 123 level = 5 |
133 else: | 124 else: |
134 level = 4 | 125 level = 4 |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 snapshot("checking description") | 1006 snapshot("checking description") |
1016 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 1007 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
1017 input_api, output_api)) | 1008 input_api, output_api)) |
1018 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( | 1009 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( |
1019 input_api, output_api)) | 1010 input_api, output_api)) |
1020 snapshot("checking do not submit in files") | 1011 snapshot("checking do not submit in files") |
1021 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( | 1012 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( |
1022 input_api, output_api)) | 1013 input_api, output_api)) |
1023 snapshot("done") | 1014 snapshot("done") |
1024 return results | 1015 return results |
OLD | NEW |