From f392703d63117ea1b135b94c9d327002def60caf Mon Sep 17 00:00:00 2001 From: Dan Beam Date: Mon, 6 Jan 2020 16:35:14 +0000 Subject: [PATCH] Exclude ES imports from long lines check Bug: 1028829 Change-Id: Iafc40952e402884639543436281e93942c0257a8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1959813 Auto-Submit: Dan Beam Commit-Queue: Edward Lesmes Reviewed-by: Edward Lesmes --- presubmit_canned_checks.py | 2 +- tests/presubmit_unittest.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 2e33374f6..76cab04c8 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -416,7 +416,7 @@ def CheckLongLines(input_api, output_api, maxlen, source_file_filter=None): JAVA_FILE_EXTS = ('java',) JAVA_EXCEPTIONS = ('import ', 'package ') JS_FILE_EXTS = ('js',) - JS_EXCEPTIONS = ("GEN('#include",) + JS_EXCEPTIONS = ("GEN('#include", 'import ') OBJC_FILE_EXTS = ('h', 'm', 'mm') OBJC_EXCEPTIONS = ('#define', '#endif', '#if', '#import', '#include', '#pragma') diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index ab3aa630e..232037b00 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -1511,6 +1511,13 @@ class CannedChecksUnittest(PresubmitTestsBase): 'bfoo', 'cfoo', 'dfoo'] + # It falls back to ChangedContents when there is a failure. This is an + # optimization since NewContents() is much faster to execute than + # ChangedContents(). + affected_file1.ChangedContents.return_value = [ + (42, content1), + (43, 'hfoo'), + (23, 'ifoo')] change2 = presubmit.Change( 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None) @@ -1525,14 +1532,10 @@ class CannedChecksUnittest(PresubmitTestsBase): 'efoo', 'ffoo', 'gfoo'] - # It falls back to ChangedContents when there is a failure. This is an - # optimization since NewContents() is much faster to execute than - # ChangedContents(). affected_file2.ChangedContents.return_value = [ (42, content2), (43, 'hfoo'), (23, 'ifoo')] - affected_file2.LocalPath.return_value = 'foo.cc' results1 = check(input_api1, presubmit.OutputApi, None) @@ -1843,6 +1846,12 @@ the current line as well! 'foo.js', "// GEN('something');", 'foo.js', presubmit.OutputApi.PresubmitPromptWarning) + def testCannedCheckJSLongImports(self): + check = lambda x, y, _: presubmit_canned_checks.CheckLongLines(x, y, 10) + self.ContentTest(check, "import {Name, otherName} from './dir/file.js';", + 'foo.js', "// We should import something long, eh?", + 'foo.js', presubmit.OutputApi.PresubmitPromptWarning) + def testCannedCheckObjCExceptionLongLines(self): check = lambda x, y, _: presubmit_canned_checks.CheckLongLines(x, y, 80) self.ContentTest(check, '#import ' + 'A ' * 150, 'foo.mm',