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
This commit is contained in:
		@@ -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]))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user