From dd1d313152a136f80c9ac3d508d2d99d6b3dc0a8 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 31 Jan 2019 16:38:31 -0800 Subject: Expect lines to be indented 8 places when tabs are used Fixes #836 --- pycodestyle.py | 8 +++++--- testsuite/E10.py | 4 ++-- testsuite/E11.py | 3 +++ testsuite/E90.py | 2 +- testsuite/W19.py | 38 +++++++++++++++++++------------------- testsuite/test_api.py | 4 ++-- testsuite/test_shell.py | 2 +- 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/pycodestyle.py b/pycodestyle.py index 0ecd7fd..4a0d17b 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -534,9 +534,11 @@ def indentation(logical_line, previous_logical, indent_char, elif not indent_expect and indent_level > previous_indent_level: yield 0, tmpl % (3 + c, "unexpected indentation") - expected_indent_level = previous_indent_level + 4 - if indent_expect and indent_level > expected_indent_level: - yield 0, tmpl % (7, 'over-indented') + if indent_expect: + expected_indent_amount = 8 if indent_char == '\t' else 4 + expected_indent_level = previous_indent_level + expected_indent_amount + if indent_level > expected_indent_level: + yield 0, tmpl % (7, 'over-indented') @register_check diff --git a/testsuite/E10.py b/testsuite/E10.py index 08b03a0..7b42594 100644 --- a/testsuite/E10.py +++ b/testsuite/E10.py @@ -3,7 +3,7 @@ for a in 'abc': for b in 'xyz': print a # indented with 8 spaces print b # indented with 1 tab -#: E101 E117 E122 W191 W191 +#: E101 E122 W191 W191 if True: pass @@ -27,7 +27,7 @@ class TestP4Poller(unittest.TestCase): pass # -#: E101 E117 W191 W191 +#: E101 W191 W191 if True: foo(1, 2) diff --git a/testsuite/E11.py b/testsuite/E11.py index c7b11d1..ef87d92 100644 --- a/testsuite/E11.py +++ b/testsuite/E11.py @@ -37,3 +37,6 @@ def start(self): #: E117 def start(): print +#: E117 W191 +def start(): + print diff --git a/testsuite/E90.py b/testsuite/E90.py index 3fd2b32..2c18e9a 100644 --- a/testsuite/E90.py +++ b/testsuite/E90.py @@ -2,7 +2,7 @@ } #: E901 = [x -#: E901 E101 E117 W191 +#: E901 E101 W191 while True: try: pass diff --git a/testsuite/W19.py b/testsuite/W19.py index d77bc9e..ed69e2b 100644 --- a/testsuite/W19.py +++ b/testsuite/W19.py @@ -1,4 +1,4 @@ -#: E117 W191 +#: W191 if False: print # indented with 1 tab #: @@ -7,30 +7,30 @@ if False: #: W191 y = x == 2 \ or x == 3 -#: E101 E117 W191 W504 +#: E101 W191 W504 if ( x == ( 3 ) or y == 4): pass -#: E101 E117 W191 +#: E101 W191 if x == 2 \ or y > 1 \ or x == 3: pass -#: E101 E117 W191 +#: E101 W191 if x == 2 \ or y > 1 \ or x == 3: pass #: -#: E101 E117 W191 W504 +#: E101 W191 W504 if (foo == bar and baz == frop): pass -#: E101 E117 W191 W504 +#: E101 W191 W504 if ( foo == bar and baz == frop @@ -38,25 +38,25 @@ if ( pass #: -#: E101 E101 E117 W191 W191 +#: E101 E101 W191 W191 if start[1] > end_col and not ( over_indent == 4 and indent_next): return(0, "E121 continuation line over-" "indented for visual indent") #: -#: E101 E117 W191 +#: E101 W191 def long_function_name( var_one, var_two, var_three, var_four): print(var_one) -#: E101 E117 W191 W504 +#: E101 W191 W504 if ((row < 0 or self.moduleCount <= row or col < 0 or self.moduleCount <= col)): raise Exception("%s,%s - %s" % (row, col, self.moduleCount)) -#: E101 E101 E101 E101 E117 W191 W191 W191 W191 W191 W191 +#: E101 E101 E101 E101 W191 W191 W191 W191 W191 W191 if bar: return( start, 'E121 lines starting with a ' @@ -65,35 +65,35 @@ if bar: "bracket's line" ) # -#: E101 E117 W191 W504 +#: E101 W191 W504 # you want vertical alignment, so use a parens if ((foo.bar("baz") and foo.bar("frop") )): print "yes" -#: E101 E117 W191 W504 +#: E101 W191 W504 # also ok, but starting to look like LISP if ((foo.bar("baz") and foo.bar("frop"))): print "yes" -#: E101 E117 W191 W504 +#: E101 W191 W504 if (a == 2 or b == "abc def ghi" "jkl mno"): return True -#: E101 E117 W191 W504 +#: E101 W191 W504 if (a == 2 or b == """abc def ghi jkl mno"""): return True -#: W191:2:1 W191:3:1 E101:3:2 E117 +#: W191:2:1 W191:3:1 E101:3:2 if length > options.max_line_length: return options.max_line_length, \ "E501 line too long (%d characters)" % length # -#: E101 E117 W191 W191 W504 +#: E101 W191 W191 W504 if os.path.exists(os.path.join(path, PEP8_BIN)): cmd = ([os.path.join(path, PEP8_BIN)] + self._pep8_options(targetfile)) @@ -119,19 +119,19 @@ or long long long long long long long long long long long long long long long lo even though the noqa comment is not immediately after the string ''' + foo # noqa # -#: E101 E117 W191 +#: E101 W191 if foo is None and bar is "frop" and \ blah == 'yeah': blah = 'yeahnah' # -#: E117 W191 W191 W191 +#: W191 W191 W191 if True: foo( 1, 2) -#: E117 W191 W191 W191 W191 W191 +#: W191 W191 W191 W191 W191 def test_keys(self): """areas.json - All regions are accounted for.""" expected = set([ diff --git a/testsuite/test_api.py b/testsuite/test_api.py index ddc28b8..c69e54d 100644 --- a/testsuite/test_api.py +++ b/testsuite/test_api.py @@ -125,7 +125,7 @@ class APITestCase(unittest.TestCase): report = pycodestyle.StyleGuide().check_files([E11]) stdout = sys.stdout.getvalue().splitlines() self.assertEqual(len(stdout), report.total_errors) - self.assertEqual(report.total_errors, 20) + self.assertEqual(report.total_errors, 24) self.assertFalse(sys.stderr) self.reset() @@ -133,7 +133,7 @@ class APITestCase(unittest.TestCase): report = pycodestyle.StyleGuide(paths=[E11]).check_files() stdout = sys.stdout.getvalue().splitlines() self.assertEqual(len(stdout), report.total_errors) - self.assertEqual(report.total_errors, 20) + self.assertEqual(report.total_errors, 24) self.assertFalse(sys.stderr) self.reset() diff --git a/testsuite/test_shell.py b/testsuite/test_shell.py index e4d0871..3878194 100644 --- a/testsuite/test_shell.py +++ b/testsuite/test_shell.py @@ -77,7 +77,7 @@ class ShellTestCase(unittest.TestCase): stdout = stdout.splitlines() self.assertEqual(errcode, 1) self.assertFalse(stderr) - self.assertEqual(len(stdout), 20) + self.assertEqual(len(stdout), 24) for line, num, col in zip(stdout, (3, 6, 6, 9, 12), (3, 6, 6, 1, 5)): path, x, y, msg = line.split(':') self.assertTrue(path.endswith(E11)) -- cgit v1.2.1