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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 file_filter = lambda x : x | 83 file_filter = lambda x : x |
84 keyword = 'DO NOT ''SUBMIT' | 84 keyword = 'DO NOT ''SUBMIT' |
85 errors = _FindNewViolationsOfRule(lambda _, line : keyword not in line, | 85 errors = _FindNewViolationsOfRule(lambda _, line : keyword not in line, |
86 input_api, file_filter) | 86 input_api, file_filter) |
87 text = '\n'.join('Found %s in %s' % (keyword, loc) for loc in errors) | 87 text = '\n'.join('Found %s in %s' % (keyword, loc) for loc in errors) |
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 lint_filters=None): | |
94 """Checks that all '.cc' and '.h' files pass cpplint.py.""" | 95 """Checks that all '.cc' and '.h' files pass cpplint.py.""" |
95 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') | 96 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') |
96 result = [] | 97 result = [] |
97 | 98 |
98 cpplint = input_api.cpplint | 99 cpplint = input_api.cpplint |
99 # Access to a protected member _XX of a client class | 100 # Access to a protected member _XX of a client class |
100 # pylint: disable=W0212 | 101 # pylint: disable=W0212 |
101 cpplint._cpplint_state.ResetErrorCounts() | 102 cpplint._cpplint_state.ResetErrorCounts() |
102 | 103 |
103 # Justifications for each filter: | 104 if lint_filters != None: |
agable
2014/12/09 21:34:48
s/!=/is not/
| |
104 # | 105 cpplint._SetFilters(lint_filters) |
105 # - build/include : Too many; fix in the future. | 106 else: |
106 # - build/include_order : Not happening; #ifdefed includes. | 107 # Justifications for each filter: |
107 # - build/namespace : I'm surprised by how often we violate this rule. | 108 # |
108 # - readability/casting : Mistakes a whole bunch of function pointer. | 109 # - build/include : Too many; fix in the future. |
tfarina
2014/12/08 01:05:39
I want to enable these checks in app_list, as we c
Dirk Pranke
2014/12/09 21:17:07
It looks like ui/app_list/PRESUBMIT.py has its own
| |
109 # - runtime/int : Can be fixed long term; volume of errors too high | 110 # - build/include_order : Not happening; #ifdefed includes. |
110 # - runtime/virtual : Broken now, but can be fixed in the future? | 111 # - build/namespace : I'm surprised by how often we violate this rule. |
111 # - whitespace/braces : We have a lot of explicit scoping in chrome code. | 112 # - readability/casting : Mistakes a whole bunch of function pointer. |
112 # - readability/inheritance : Temporary, while the OVERRIDE and FINAL fixup | 113 # - runtime/int : Can be fixed long term; volume of errors too high |
113 # is in progress. | 114 # - runtime/virtual : Broken now, but can be fixed in the future? |
114 cpplint._SetFilters('-build/include,-build/include_order,-build/namespace,' | 115 # - whitespace/braces : We have a lot of explicit scoping in chrome code. |
115 '-readability/casting,-runtime/int,-runtime/virtual,' | 116 # - readability/inheritance : Temporary, while the OVERRIDE and FINAL fixup |
116 '-whitespace/braces,-readability/inheritance') | 117 # is in progress. |
118 cpplint._SetFilters('-build/include,-build/include_order,-build/namespace,' | |
119 '-readability/casting,-runtime/int,-runtime/virtual,' | |
120 '-whitespace/braces,-readability/inheritance') | |
117 | 121 |
118 # We currently are more strict with normal code than unit tests; 4 and 5 are | 122 # We currently are more strict with normal code than unit tests; 4 and 5 are |
119 # the verbosity level that would normally be passed to cpplint.py through | 123 # the verbosity level that would normally be passed to cpplint.py through |
120 # --verbose=#. Hopefully, in the future, we can be more verbose. | 124 # --verbose=#. Hopefully, in the future, we can be more verbose. |
121 files = [f.AbsoluteLocalPath() for f in | 125 files = [f.AbsoluteLocalPath() for f in |
122 input_api.AffectedSourceFiles(source_file_filter)] | 126 input_api.AffectedSourceFiles(source_file_filter)] |
123 for file_name in files: | 127 for file_name in files: |
124 if _RE_IS_TEST.match(file_name): | 128 if _RE_IS_TEST.match(file_name): |
125 level = 5 | 129 level = 5 |
126 else: | 130 else: |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 for f in affected_files: | 1129 for f in affected_files: |
1126 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1130 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
1127 rc = gn.main(cmd) | 1131 rc = gn.main(cmd) |
1128 if rc == 2: | 1132 if rc == 2: |
1129 warnings.append(output_api.PresubmitPromptWarning( | 1133 warnings.append(output_api.PresubmitPromptWarning( |
1130 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1134 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
1131 f.AbsoluteLocalPath(), f.LocalPath()))) | 1135 f.AbsoluteLocalPath(), f.LocalPath()))) |
1132 # It's just a warning, so ignore other types of failures assuming they'll be | 1136 # It's just a warning, so ignore other types of failures assuming they'll be |
1133 # caught elsewhere. | 1137 # caught elsewhere. |
1134 return warnings | 1138 return warnings |
OLD | NEW |