diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index e55c92c06b..4342110e45 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -323,7 +323,14 @@ def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None): # 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 ') + def no_long_lines(file_extension, line): + # Allow special java statements to be as long as neccessary. + if file_extension == 'java' and line.startswith(SPECIAL_JAVA_STARTS): + return True + file_maxlen = maxlens.get(file_extension, maxlens['']) # Stupidly long symbols that needs to be worked around if takes 66% of line. long_symbol = file_maxlen * 2 / 3 diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 3b814f0e97..24890e8c58 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -1828,6 +1828,12 @@ class CannedChecksUnittest(PresubmitTestsBase): self.ContentTest(check, 'A ' * 50, 'foo.java', 'A ' * 50 + 'B', 'foo.java', presubmit.OutputApi.PresubmitPromptWarning) + def testCannedCheckSpecialJavaLongLines(self): + check = lambda x, y, _: presubmit_canned_checks.CheckLongLines(x, y) + self.ContentTest(check, 'import ' + 'A ' * 150, 'foo.java', + 'importSomething ' + 'A ' * 50, 'foo.java', + presubmit.OutputApi.PresubmitPromptWarning) + def testCannedCheckLongLinesLF(self): check = lambda x, y, z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) self.ContentTest(check, '012345678\n', None, '0123456789\n', None,