Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: presubmit_canned_checks.py

Issue 2046003002: [depot_tools] Add gendered pronoun presubmit check. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: test Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 # Justifications for each filter: 10 # Justifications for each filter:
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 outputs = [] 204 outputs = []
205 if cr_files: 205 if cr_files:
206 outputs.append(output_api.PresubmitPromptWarning( 206 outputs.append(output_api.PresubmitPromptWarning(
207 'Found a CR character in these files:', items=cr_files)) 207 'Found a CR character in these files:', items=cr_files))
208 if eof_files: 208 if eof_files:
209 outputs.append(output_api.PresubmitPromptWarning( 209 outputs.append(output_api.PresubmitPromptWarning(
210 'These files should end in one (and only one) newline character:', 210 'These files should end in one (and only one) newline character:',
211 items=eof_files)) 211 items=eof_files))
212 return outputs 212 return outputs
213 213
214 def CheckGenderNeutral(input_api, output_api, source_file_filter=None):
215 """Checks that there are no gendered pronouns in any of the text files to be
216 submitted.
217 """
218 gendered_re = input_api.re.compile(
219 '(^|\s|\(|\[)([Hh]e|[Hh]is|[Hh]ers?|[Hh]im|[Ss]he|[Gg]uys?)\\b')
220
221 errors = []
222 for f in input_api.AffectedFiles(include_deletes=False,
223 file_filter=source_file_filter):
224 for line_num, line in f.ChangedContents():
225 if gendered_re.search(line):
226 errors.append('%s (%d): %s' % (f.LocalPath(), line_num, line))
227
228 if len(errors):
229 return [output_api.PresubmitPromptWarning('Found a gendered pronoun in:',
230 long_text='\n'.join(errors))]
231 return []
232
233
214 234
215 def _ReportErrorFileAndLine(filename, line_num, dummy_line): 235 def _ReportErrorFileAndLine(filename, line_num, dummy_line):
216 """Default error formatter for _FindNewViolationsOfRule.""" 236 """Default error formatter for _FindNewViolationsOfRule."""
217 return '%s:%s' % (filename, line_num) 237 return '%s:%s' % (filename, line_num)
218 238
219 239
220 def _FindNewViolationsOfRule(callable_rule, input_api, source_file_filter=None, 240 def _FindNewViolationsOfRule(callable_rule, input_api, source_file_filter=None,
221 error_formatter=_ReportErrorFileAndLine): 241 error_formatter=_ReportErrorFileAndLine):
222 """Find all newly introduced violations of a per-line rule (a callable). 242 """Find all newly introduced violations of a per-line rule (a callable).
223 243
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 for f in affected_files: 1175 for f in affected_files:
1156 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] 1176 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()]
1157 rc = gn.main(cmd) 1177 rc = gn.main(cmd)
1158 if rc == 2: 1178 if rc == 2:
1159 warnings.append(output_api.PresubmitPromptWarning( 1179 warnings.append(output_api.PresubmitPromptWarning(
1160 '%s requires formatting. Please run `gn format --in-place %s`.' % ( 1180 '%s requires formatting. Please run `gn format --in-place %s`.' % (
1161 f.AbsoluteLocalPath(), f.LocalPath()))) 1181 f.AbsoluteLocalPath(), f.LocalPath())))
1162 # It's just a warning, so ignore other types of failures assuming they'll be 1182 # It's just a warning, so ignore other types of failures assuming they'll be
1163 # caught elsewhere. 1183 # caught elsewhere.
1164 return warnings 1184 return warnings
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698