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

Side by Side Diff: presubmit_canned_checks.py

Issue 100163002: Allow obj-c import statements to be as long as necessary. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: The alphabet is confusing. Sort correctly. Created 7 years 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 10
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 def CheckLongLines(input_api, output_api, maxlen, source_file_filter=None): 314 def CheckLongLines(input_api, output_api, maxlen, source_file_filter=None):
315 """Checks that there aren't any lines longer than maxlen characters in any of 315 """Checks that there aren't any lines longer than maxlen characters in any of
316 the text files to be submitted. 316 the text files to be submitted.
317 """ 317 """
318 maxlens = { 318 maxlens = {
319 'java': 100, 319 'java': 100,
320 # This is specifically for Android's handwritten makefiles (Android.mk). 320 # This is specifically for Android's handwritten makefiles (Android.mk).
321 'mk': 200, 321 'mk': 200,
322 '': maxlen, 322 '': maxlen,
323 } 323 }
324 # Note: these are C++ specific but processed on all languages. :(
325 MACROS = ('#define', '#include', '#import', '#pragma', '#if', '#endif')
326 324
327 # Special java statements. 325 # Language specific exceptions to max line length.
328 SPECIAL_JAVA_STARTS = ('package ', 'import ') 326 # '.h' is considered an obj-c file extension, since OBJC_EXCEPTIONS are a
327 # superset of CPP_EXCEPTIONS.
328 CPP_FILE_EXTS = ('c', 'cc')
329 CPP_EXCEPTIONS = ('#define', '#endif', '#if', '#include', '#pragma')
330 JAVA_FILE_EXTS = ('java',)
331 JAVA_EXCEPTIONS = ('import ', 'package ')
332 OBJC_FILE_EXTS = ('h', 'm', 'mm')
333 OBJC_EXCEPTIONS = ('#define', '#endif', '#if', '#import', '#include',
334 '#pragma')
335
336 LANGUAGE_EXCEPTIONS = [
337 (CPP_FILE_EXTS, CPP_EXCEPTIONS),
338 (JAVA_FILE_EXTS, JAVA_EXCEPTIONS),
339 (OBJC_FILE_EXTS, OBJC_EXCEPTIONS),
340 ]
329 341
330 def no_long_lines(file_extension, line): 342 def no_long_lines(file_extension, line):
331 # Allow special java statements to be as long as necessary. 343 # Check for language specific exceptions.
332 if file_extension == 'java' and line.startswith(SPECIAL_JAVA_STARTS): 344 if any(file_extension in exts and line.startswith(exceptions)
345 for exts, exceptions in LANGUAGE_EXCEPTIONS):
333 return True 346 return True
334 347
335 file_maxlen = maxlens.get(file_extension, maxlens['']) 348 file_maxlen = maxlens.get(file_extension, maxlens[''])
336 # Stupidly long symbols that needs to be worked around if takes 66% of line. 349 # Stupidly long symbols that needs to be worked around if takes 66% of line.
337 long_symbol = file_maxlen * 2 / 3 350 long_symbol = file_maxlen * 2 / 3
338 # Hard line length limit at 50% more. 351 # Hard line length limit at 50% more.
339 extra_maxlen = file_maxlen * 3 / 2 352 extra_maxlen = file_maxlen * 3 / 2
340 353
341 line_len = len(line) 354 line_len = len(line)
342 if line_len <= file_maxlen: 355 if line_len <= file_maxlen:
343 return True 356 return True
344 357
345 if line_len > extra_maxlen: 358 if line_len > extra_maxlen:
346 return False 359 return False
347 360
348 return ( 361 return (
349 line.startswith(MACROS) or
350 any((url in line) for url in ('http://', 'https://')) or 362 any((url in line) for url in ('http://', 'https://')) or
351 input_api.re.match( 363 input_api.re.match(
352 r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, line)) 364 r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, line))
353 365
354 def format_error(filename, line_num, line): 366 def format_error(filename, line_num, line):
355 return '%s, line %s, %s chars' % (filename, line_num, len(line)) 367 return '%s, line %s, %s chars' % (filename, line_num, len(line))
356 368
357 errors = _FindNewViolationsOfRule(no_long_lines, input_api, 369 errors = _FindNewViolationsOfRule(no_long_lines, input_api,
358 source_file_filter, 370 source_file_filter,
359 error_formatter=format_error) 371 error_formatter=format_error)
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 snapshot("checking description") 1035 snapshot("checking description")
1024 results.extend(input_api.canned_checks.CheckChangeHasDescription( 1036 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1025 input_api, output_api)) 1037 input_api, output_api))
1026 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( 1038 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription(
1027 input_api, output_api)) 1039 input_api, output_api))
1028 snapshot("checking do not submit in files") 1040 snapshot("checking do not submit in files")
1029 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( 1041 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles(
1030 input_api, output_api)) 1042 input_api, output_api))
1031 snapshot("done") 1043 snapshot("done")
1032 return results 1044 return results
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