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 # Justifications for each filter: | 10 # Justifications for each filter: |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 extra_maxlen = file_maxlen * 3 / 2 | 335 extra_maxlen = file_maxlen * 3 / 2 |
336 | 336 |
337 line_len = len(line) | 337 line_len = len(line) |
338 if line_len <= file_maxlen: | 338 if line_len <= file_maxlen: |
339 return True | 339 return True |
340 | 340 |
341 # Allow long URLs of any length. | 341 # Allow long URLs of any length. |
342 if any((url in line) for url in ('file://', 'http://', 'https://')): | 342 if any((url in line) for url in ('file://', 'http://', 'https://')): |
343 return True | 343 return True |
344 | 344 |
| 345 # If 'line-too-long' is explictly suppressed for the line, any length is |
| 346 # acceptable. |
| 347 if 'pylint: disable=line-too-long' in line and file_extension == 'py': |
| 348 return True |
| 349 |
345 if line_len > extra_maxlen: | 350 if line_len > extra_maxlen: |
346 return False | 351 return False |
347 | 352 |
348 if 'url(' in line and file_extension == 'css': | 353 if 'url(' in line and file_extension == 'css': |
349 return True | 354 return True |
350 | 355 |
351 if '<include' in line and file_extension in ('css', 'html', 'js'): | 356 if '<include' in line and file_extension in ('css', 'html', 'js'): |
352 return True | 357 return True |
353 | 358 |
354 if 'pylint: disable=line-too-long' in line and file_extension == 'py': | |
355 return True | |
356 | |
357 return input_api.re.match( | 359 return input_api.re.match( |
358 r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, line) | 360 r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, line) |
359 | 361 |
360 def format_error(filename, line_num, line): | 362 def format_error(filename, line_num, line): |
361 return '%s, line %s, %s chars' % (filename, line_num, len(line)) | 363 return '%s, line %s, %s chars' % (filename, line_num, len(line)) |
362 | 364 |
363 errors = _FindNewViolationsOfRule(no_long_lines, input_api, | 365 errors = _FindNewViolationsOfRule(no_long_lines, input_api, |
364 source_file_filter, | 366 source_file_filter, |
365 error_formatter=format_error) | 367 error_formatter=format_error) |
366 if errors: | 368 if errors: |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 for f in affected_files: | 1118 for f in affected_files: |
1117 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1119 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
1118 rc = gn.main(cmd) | 1120 rc = gn.main(cmd) |
1119 if rc == 2: | 1121 if rc == 2: |
1120 warnings.append(output_api.PresubmitPromptWarning( | 1122 warnings.append(output_api.PresubmitPromptWarning( |
1121 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1123 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
1122 f.AbsoluteLocalPath(), f.LocalPath()))) | 1124 f.AbsoluteLocalPath(), f.LocalPath()))) |
1123 # It's just a warning, so ignore other types of failures assuming they'll be | 1125 # It's just a warning, so ignore other types of failures assuming they'll be |
1124 # caught elsewhere. | 1126 # caught elsewhere. |
1125 return warnings | 1127 return warnings |
OLD | NEW |