Chromium Code Reviews| 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 # Hard line length limit at 50% more. | 351 # Hard line length limit at 50% more. |
| 352 extra_maxlen = file_maxlen * 3 / 2 | 352 extra_maxlen = file_maxlen * 3 / 2 |
| 353 | 353 |
| 354 line_len = len(line) | 354 line_len = len(line) |
| 355 if line_len <= file_maxlen: | 355 if line_len <= file_maxlen: |
| 356 return True | 356 return True |
| 357 | 357 |
| 358 if line_len > extra_maxlen: | 358 if line_len > extra_maxlen: |
| 359 return False | 359 return False |
| 360 | 360 |
| 361 return ( | 361 if (any((url in line) for url in ('file://', 'http://', 'https://')) or |
|
M-A Ruel
2014/07/28 13:43:31
It's really two separate checks so I'd split it tw
Marc Treib
2014/07/28 13:57:11
Done.
| |
| 362 any((url in line) for url in ('file://', 'http://', 'https://')) or | 362 ('url(' in line) and file_extension == 'css'): |
| 363 input_api.re.match( | 363 return True |
| 364 r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, line)) | 364 |
| 365 return input_api.re.match(r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, | |
| 366 line) | |
| 365 | 367 |
| 366 def format_error(filename, line_num, line): | 368 def format_error(filename, line_num, line): |
| 367 return '%s, line %s, %s chars' % (filename, line_num, len(line)) | 369 return '%s, line %s, %s chars' % (filename, line_num, len(line)) |
| 368 | 370 |
| 369 errors = _FindNewViolationsOfRule(no_long_lines, input_api, | 371 errors = _FindNewViolationsOfRule(no_long_lines, input_api, |
| 370 source_file_filter, | 372 source_file_filter, |
| 371 error_formatter=format_error) | 373 error_formatter=format_error) |
| 372 if errors: | 374 if errors: |
| 373 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen | 375 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen |
| 374 return [output_api.PresubmitPromptWarning(msg, items=errors[:5])] | 376 return [output_api.PresubmitPromptWarning(msg, items=errors[:5])] |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1094 def CheckPatchFormatted(input_api, output_api): | 1096 def CheckPatchFormatted(input_api, output_api): |
| 1095 import git_cl | 1097 import git_cl |
| 1096 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] | 1098 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] |
| 1097 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) | 1099 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) |
| 1098 if code == 2: | 1100 if code == 2: |
| 1099 return [output_api.PresubmitPromptWarning( | 1101 return [output_api.PresubmitPromptWarning( |
| 1100 'Your patch is not formatted, please run git cl format.')] | 1102 'Your patch is not formatted, please run git cl format.')] |
| 1101 # As this is just a warning, ignore all other errors if the user | 1103 # As this is just a warning, ignore all other errors if the user |
| 1102 # happens to have a broken clang-format, doesn't use git, etc etc. | 1104 # happens to have a broken clang-format, doesn't use git, etc etc. |
| 1103 return [] | 1105 return [] |
| OLD | NEW |