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://')): |
362 any((url in line) for url in ('file://', 'http://', 'https://')) or | 362 return True |
363 input_api.re.match( | 363 |
364 r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, line)) | 364 if 'url(' in line and file_extension == 'css': |
| 365 return True |
| 366 |
| 367 return input_api.re.match( |
| 368 r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, line) |
365 | 369 |
366 def format_error(filename, line_num, line): | 370 def format_error(filename, line_num, line): |
367 return '%s, line %s, %s chars' % (filename, line_num, len(line)) | 371 return '%s, line %s, %s chars' % (filename, line_num, len(line)) |
368 | 372 |
369 errors = _FindNewViolationsOfRule(no_long_lines, input_api, | 373 errors = _FindNewViolationsOfRule(no_long_lines, input_api, |
370 source_file_filter, | 374 source_file_filter, |
371 error_formatter=format_error) | 375 error_formatter=format_error) |
372 if errors: | 376 if errors: |
373 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen | 377 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen |
374 return [output_api.PresubmitPromptWarning(msg, items=errors[:5])] | 378 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): | 1098 def CheckPatchFormatted(input_api, output_api): |
1095 import git_cl | 1099 import git_cl |
1096 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] | 1100 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] |
1097 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) | 1101 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) |
1098 if code == 2: | 1102 if code == 2: |
1099 return [output_api.PresubmitPromptWarning( | 1103 return [output_api.PresubmitPromptWarning( |
1100 'Your patch is not formatted, please run git cl format.')] | 1104 'Your patch is not formatted, please run git cl format.')] |
1101 # As this is just a warning, ignore all other errors if the user | 1105 # 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. | 1106 # happens to have a broken clang-format, doesn't use git, etc etc. |
1103 return [] | 1107 return [] |
OLD | NEW |