summaryrefslogtreecommitdiff
path: root/pycodestyle.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2017-11-05 15:46:52 -0800
committerJon Dufresne <jon.dufresne@gmail.com>2019-01-24 18:04:21 -0800
commit68335d1a6d65de7ed09af580bdb909c5f6c139c2 (patch)
treee5759cfc7eb5a1ebe430274d1695d61ab7dfc836 /pycodestyle.py
parentdb80d0750951e4a9d1ac82338285496534d6c061 (diff)
downloadpep8-68335d1a6d65de7ed09af580bdb909c5f6c139c2.tar.gz
Add check for over-indented blocks
In a project with all lines indented 4 spaces, I noticed pycodestyle was not catching code that was accidentally indented two levels (8 spaces). The over indentation was unintended and can be caught during static analysis. Fixes #430
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-xpycodestyle.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 094e24f..766e6bd 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -207,7 +207,7 @@ def tabs_or_spaces(physical_line, indent_char):
tabs and spaces. When using -tt these warnings become errors.
These options are highly recommended!
- Okay: if a == 0:\n a = 1\n b = 1
+ Okay: if a == 0:\n a = 1\n b = 1
E101: if a == 0:\n a = 1\n\tb = 1
"""
indent = INDENT_REGEX.match(physical_line).group(1)
@@ -534,6 +534,10 @@ 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')
+
@register_check
def continued_indentation(logical_line, tokens, indent_level, hang_closing,