Chromium Code Reviews| Index: presubmit_canned_checks.py |
| diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py |
| index 816c7840a4b2bbd290b902853788220337bb9ded..74c838dff1b31107eb39f638d113a205caaa6b3a 100644 |
| --- a/presubmit_canned_checks.py |
| +++ b/presubmit_canned_checks.py |
| @@ -321,16 +321,29 @@ def CheckLongLines(input_api, output_api, maxlen, source_file_filter=None): |
| 'mk': 200, |
| '': maxlen, |
| } |
| - # Note: these are C++ specific but processed on all languages. :( |
| - MACROS = ('#define', '#include', '#import', '#pragma', '#if', '#endif') |
| - # Special java statements. |
| - SPECIAL_JAVA_STARTS = ('package ', 'import ') |
| + # Language specific exceptions to max line length. |
| + # '.h' files count as obj-c, since OBJC_EXCPTS are a superset of CPP_EXCPTS. |
| + CPP_FILE_EXTS = ('c', 'cc') |
| + CPP_EXCPTS = ('#define', '#include', '#import', '#pragma', '#if', '#endif') |
| + JAVA_FILE_EXTS = ('java') |
|
M-A Ruel
2013/12/02 23:56:27
This was not doing what you thought it was doing.
erikchen2
2013/12/03 00:20:09
ack, thanks
|
| + JAVA_EXCPTS = ('package ', 'import ') |
|
M-A Ruel
2013/12/02 23:56:27
sort
erikchen2
2013/12/03 00:20:09
Done.
|
| + OBJC_FILE_EXTS = ('h', 'm', 'mm') |
| + OBJC_EXCPTS = ('#define', '#include', '#import', '#pragma', '#if', |
| + '#endif', '#import') |
|
M-A Ruel
2013/12/02 23:56:27
duplicate of #import
erikchen2
2013/12/03 00:20:09
Done.
|
| + |
| + LANGUAGE_EXCEPTIONS = [ |
|
M-A Ruel
2013/12/02 23:56:27
I'd used a list of tuple instead.
LANGUAGE_EXCEPTI
erikchen2
2013/12/03 00:20:09
Done.
|
| + {'extensions' : CPP_FILE_EXTS, 'excpts' : CPP_EXCPTS}, |
| + {'extensions' : JAVA_FILE_EXTS, 'excpts' : JAVA_EXCPTS}, |
| + {'extensions' : OBJC_FILE_EXTS, 'excpts' : OBJC_EXCPTS}, |
| + ] |
| def no_long_lines(file_extension, line): |
| - # Allow special java statements to be as long as necessary. |
| - if file_extension == 'java' and line.startswith(SPECIAL_JAVA_STARTS): |
| - return True |
| + # Check for language specific exceptions. |
| + for language in LANGUAGE_EXCEPTIONS: |
|
M-A Ruel
2013/12/02 23:56:27
if any(
file_extensions in ext and line.starts
erikchen2
2013/12/03 00:20:09
Done.
|
| + if (file_extension in language['extensions'] and |
| + line.startswith(language['excpts'])): |
| + return True |
| file_maxlen = maxlens.get(file_extension, maxlens['']) |
| # Stupidly long symbols that needs to be worked around if takes 66% of line. |
| @@ -346,7 +359,6 @@ def CheckLongLines(input_api, output_api, maxlen, source_file_filter=None): |
| return False |
| return ( |
| - line.startswith(MACROS) or |
| any((url in line) for url in ('http://', 'https://')) or |
| input_api.re.match( |
| r'.*[A-Za-z][A-Za-z_0-9]{%d,}.*' % long_symbol, line)) |