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

Unified Diff: presubmit_canned_checks.py

Issue 7097012: Improve CheckLongLines() to increase the hard limit at 50% when an exception is found. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix regex to work properly, update unit test accordingly Created 9 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_canned_checks.py
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py
index 469578e885b1f274c1810483fa8fff2b691e7c10..4f267ca6677959d5e8c954dff8067cc77c4bd57c 100644
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -302,13 +302,25 @@ def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None):
"""Checks that there aren't any lines longer than maxlen characters in any of
the text files to be submitted.
"""
+ # Stupidly long symbols that needs to be worked around if takes 66% of line.
+ long_symbol = maxlen * 2 / 3
+ # Hard line length limit at 50% more.
+ extra_maxlen = maxlen * 3 / 2
+ # Note: these are C++ specific but processed on all languages. :(
+ MACROS = ('#define', '#include', '#import', '#pragma', '#if', '#endif')
+
def no_long_lines(line):
- # Allow lines with http://, https:// and #define/#pragma/#include/#if/#endif
- # to exceed the maxlen rule.
- return (len(line) <= maxlen or
- any((url in line) for url in ('http://', 'https://')) or
- line.startswith(('#define', '#include', '#import', '#pragma',
- '#if', '#endif')))
+ if len(line) <= maxlen:
+ return True
+
+ if len(line) > extra_maxlen:
+ return False
+
+ return (
+ line.startswith(MACROS) or
Dirk Pranke 2011/06/20 18:19:22 Hm. Didn't realize you can use tuples here. Cool.
+ 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))
def format_error(filename, line_num, line):
return '%s, line %s, %s chars' % (filename, line_num, len(line))
« 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