Skip to content

Commit 3fbadb7

Browse files
committed
Replace codes E111/2/3 with E114/5/6 for indentation of comments; issue #274
2 parents 46a2d18 + 8a37cd9 commit 3fbadb7

File tree

6 files changed

+43
-9
lines changed

6 files changed

+43
-9
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Changelog
99

1010
* Report E704 for one-liner def instead of E701. (Issue #277)
1111

12+
* Replace codes E111, E112 and E113 with codes E114, E115 and E116
13+
for wrong indentation of comments. (Issue #274)
14+
1215

1316
1.5.7 (2014-05-29)
1417
------------------

docs/intro.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ This is the current list of error and warning codes:
194194
+----------+----------------------------------------------------------------------+
195195
| E113 | unexpected indentation |
196196
+----------+----------------------------------------------------------------------+
197+
| E114 | indentation is not a multiple of four (comment) |
198+
+----------+----------------------------------------------------------------------+
199+
| E115 | expected an indented block (comment) |
200+
+----------+----------------------------------------------------------------------+
201+
| E116 | unexpected indentation (comment) |
202+
+----------+----------------------------------------------------------------------+
197203
+----------+----------------------------------------------------------------------+
198204
| E121 (^) | continuation line under-indented for hanging indent |
199205
+----------+----------------------------------------------------------------------+

pep8.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,20 +353,25 @@ def indentation(logical_line, previous_logical, indent_char,
353353
Okay: a = 1
354354
Okay: if a == 0:\n a = 1
355355
E111: a = 1
356+
E114: # a = 1
356357
357358
Okay: for item in items:\n pass
358359
E112: for item in items:\npass
360+
E115: for item in items:\n# Hi\n pass
359361
360362
Okay: a = 1\nb = 2
361363
E113: a = 1\n b = 2
364+
E116: a = 1\n # b = 2
362365
"""
363-
if indent_char == ' ' and indent_level % 4:
364-
yield 0, "E111 indentation is not a multiple of four"
366+
c = 0 if logical_line else 3
367+
tmpl = "E11%d %s" if logical_line else "E11%d %s (comment)"
368+
if indent_level % 4:
369+
yield 0, tmpl % (1 + c, "indentation is not a multiple of four")
365370
indent_expect = previous_logical.endswith(':')
366371
if indent_expect and indent_level <= previous_indent_level:
367-
yield 0, "E112 expected an indented block"
368-
if indent_level > previous_indent_level and not indent_expect:
369-
yield 0, "E113 unexpected indentation"
372+
yield 0, tmpl % (2 + c, "expected an indented block")
373+
elif not indent_expect and indent_level > previous_indent_level:
374+
yield 0, tmpl % (3 + c, "unexpected indentation")
370375

371376

372377
def continued_indentation(logical_line, tokens, indent_level, hang_closing,

testsuite/E11.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,27 @@
1010
#: E113
1111
print
1212
print
13-
#: E111 E113
13+
#: E114 E116
1414
mimetype = 'application/x-directory'
1515
# 'httpd/unix-directory'
1616
create_date = False
17+
#: E116 E116 E116
18+
def start(self):
19+
if True:
20+
self.master.start()
21+
# try:
22+
# self.master.start()
23+
# except MasterExit:
24+
# self.shutdown()
25+
# finally:
26+
# sys.exit()
27+
#: E115 E115 E115 E115 E115 E115
28+
def start(self):
29+
if True:
30+
# try:
31+
# self.master.start()
32+
# except MasterExit:
33+
# self.shutdown()
34+
# finally:
35+
# sys.exit()
36+
self.master.start()

testsuite/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ def test_styleguide(self):
124124
report = pep8.StyleGuide().check_files([E11])
125125
stdout = sys.stdout.getvalue().splitlines()
126126
self.assertEqual(len(stdout), report.total_errors)
127-
self.assertEqual(report.total_errors, 6)
127+
self.assertEqual(report.total_errors, 17)
128128
self.assertFalse(sys.stderr)
129129
self.reset()
130130

131131
# Passing the paths in the constructor gives same result
132132
report = pep8.StyleGuide(paths=[E11]).check_files()
133133
stdout = sys.stdout.getvalue().splitlines()
134134
self.assertEqual(len(stdout), report.total_errors)
135-
self.assertEqual(report.total_errors, 6)
135+
self.assertEqual(report.total_errors, 17)
136136
self.assertFalse(sys.stderr)
137137
self.reset()
138138

testsuite/test_shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_check_simple(self):
7575
stdout = stdout.splitlines()
7676
self.assertEqual(errcode, 1)
7777
self.assertFalse(stderr)
78-
self.assertEqual(len(stdout), 6)
78+
self.assertEqual(len(stdout), 17)
7979
for line, num, col in zip(stdout, (3, 6, 9, 12), (3, 6, 1, 5)):
8080
path, x, y, msg = line.split(':')
8181
self.assertTrue(path.endswith(E11))

0 commit comments

Comments
 (0)