OLD | NEW |
---|---|
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 | 7 |
8 ### Description checks | 8 ### Description checks |
9 | 9 |
10 def CheckChangeHasTestField(input_api, output_api): | 10 def CheckChangeHasTestField(input_api, output_api): |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 return [output_api.PresubmitPromptWarning( | 295 return [output_api.PresubmitPromptWarning( |
296 'Found line ending with white spaces in:', | 296 'Found line ending with white spaces in:', |
297 long_text='\n'.join(errors))] | 297 long_text='\n'.join(errors))] |
298 return [] | 298 return [] |
299 | 299 |
300 | 300 |
301 def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None): | 301 def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None): |
302 """Checks that there aren't any lines longer than maxlen characters in any of | 302 """Checks that there aren't any lines longer than maxlen characters in any of |
303 the text files to be submitted. | 303 the text files to be submitted. |
304 """ | 304 """ |
305 # Stupidly long symbols that needs to be worked around if takes 66% of line. | |
306 long_symbol = maxlen * 2 / 3 | |
307 # Hard line length limit at 50% more. | |
308 extra_maxlen = maxlen * 3 / 2 | |
309 # Note: these are C++ specific but processed on all languages. :( | |
310 MACROS = ('#define', '#include', '#import', '#pragma', '#if', '#endif') | |
311 | |
305 def no_long_lines(line): | 312 def no_long_lines(line): |
306 # Allow lines with http://, https:// and #define/#pragma/#include/#if/#endif | 313 if len(line) <= maxlen: |
307 # to exceed the maxlen rule. | 314 return True |
308 return (len(line) <= maxlen or | 315 |
309 any((url in line) for url in ('http://', 'https://')) or | 316 if len(line) > extra_maxlen: |
310 line.startswith(('#define', '#include', '#import', '#pragma', | 317 return False |
311 '#if', '#endif'))) | 318 |
319 return ( | |
320 line.startswith(MACROS) or | |
Dirk Pranke
2011/06/20 18:19:22
Hm. Didn't realize you can use tuples here. Cool.
| |
321 any((url in line) for url in ('http://', 'https://')) or | |
322 input_api.re.match( | |
323 r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, line)) | |
312 | 324 |
313 def format_error(filename, line_num, line): | 325 def format_error(filename, line_num, line): |
314 return '%s, line %s, %s chars' % (filename, line_num, len(line)) | 326 return '%s, line %s, %s chars' % (filename, line_num, len(line)) |
315 | 327 |
316 errors = _FindNewViolationsOfRule(no_long_lines, input_api, | 328 errors = _FindNewViolationsOfRule(no_long_lines, input_api, |
317 source_file_filter, | 329 source_file_filter, |
318 error_formatter=format_error) | 330 error_formatter=format_error) |
319 if errors: | 331 if errors: |
320 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen | 332 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen |
321 return [output_api.PresubmitPromptWarning(msg, items=errors[:5])] | 333 return [output_api.PresubmitPromptWarning(msg, items=errors[:5])] |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( | 924 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( |
913 input_api, output_api, source_file_filter=text_files)) | 925 input_api, output_api, source_file_filter=text_files)) |
914 snapshot("checking svn mime types") | 926 snapshot("checking svn mime types") |
915 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 927 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
916 input_api, output_api)) | 928 input_api, output_api)) |
917 snapshot("checking license") | 929 snapshot("checking license") |
918 results.extend(input_api.canned_checks.CheckLicense( | 930 results.extend(input_api.canned_checks.CheckLicense( |
919 input_api, output_api, license_header, source_file_filter=sources)) | 931 input_api, output_api, license_header, source_file_filter=sources)) |
920 snapshot("done") | 932 snapshot("done") |
921 return results | 933 return results |
OLD | NEW |