From fcefe62547c11bae26f237572dad34546213254e Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Fri, 26 Oct 2012 20:40:36 +0000 Subject: Change hacking.py N306 to use logical_lines Only logical lines (does not include comments) should be checked for alphabetical import order. This patch changes N306 (imports not in alphabetical order) to run on logical lines not physical lines. Fixes bug 1071849 Change-Id: Ib2cb92f9eb82aeed1ff5879d3e38c8961b4f06cc --- tools/hacking.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/hacking.py b/tools/hacking.py index 4e42d3e89..4e013ae4f 100755 --- a/tools/hacking.py +++ b/tools/hacking.py @@ -250,7 +250,7 @@ def nova_import_module_only(logical_line): #TODO(jogo): import template: N305 -def nova_import_alphabetical(physical_line, line_number, lines): +def nova_import_alphabetical(logical_line, line_number, lines): """Check for imports in alphabetical order. nova HACKING guide recommendation for imports: @@ -259,7 +259,7 @@ def nova_import_alphabetical(physical_line, line_number, lines): """ # handle import x # use .lower since capitalization shouldn't dictate order - split_line = import_normalize(physical_line.strip()).lower().split() + split_line = import_normalize(logical_line.strip()).lower().split() split_previous = import_normalize(lines[line_number - 2] ).strip().lower().split() # with or without "as y" @@ -267,7 +267,7 @@ def nova_import_alphabetical(physical_line, line_number, lines): if (len(split_line) in length and len(split_previous) in length and split_line[0] == "import" and split_previous[0] == "import"): if split_line[1] < split_previous[1]: - return (0, "NOVA N306: imports not in alphabetical order (%s, %s)" + yield (0, "NOVA N306: imports not in alphabetical order (%s, %s)" % (split_previous[1], split_line[1])) -- cgit