pycodestyle.py: enhanced the 'blank lines before' test to make the reported errors more specific (introduced new error codes E307 and E308)

Sat, 21 Apr 2018 17:11:05 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 21 Apr 2018 17:11:05 +0200
changeset 6263
4dd53711d869
parent 6261
36854b779685
child 6264
04a671fa4adb

pycodestyle.py: enhanced the 'blank lines before' test to make the reported errors more specific (introduced new error codes E307 and E308)

Plugins/CheckerPlugins/CodeStyleChecker/pycodestyle.py file | annotate | diff | comparison | revisions
--- a/Plugins/CheckerPlugins/CodeStyleChecker/pycodestyle.py	Thu Apr 19 19:33:14 2018 +0200
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/pycodestyle.py	Sat Apr 21 17:11:05 2018 +0200
@@ -347,10 +347,11 @@
     E302: def a():\n    pass\n\ndef b(n):\n    pass
     E302: def a():\n    pass\n\nasync def b(n):\n    pass
     E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
-    E303: def a():\n\n\n\n    pass
     E304: @decorator\n\ndef a():\n    pass
     E305: def a():\n    pass\na()
     E306: def a():\n    def b():\n        pass\n    def c():\n        pass
+    E307: def a():\n    def b():\n        pass\n\n\n    def c():\n        pass
+    E308: def a():\n\n\n\n    pass
     """
     top_level_lines = BLANK_LINES_CONFIG['top_level']
     method_lines = BLANK_LINES_CONFIG['method']
@@ -363,7 +364,15 @@
     elif (blank_lines > top_level_lines or
             (indent_level and blank_lines == method_lines + 1)
           ):
-        yield 0, "E303 too many blank lines (%d)", blank_lines
+        if indent_level:
+            if previous_logical.strip().startswith(('def ', 'class ')):
+                yield (0,  "E308 too many blank lines (%d)", blank_lines)
+            else:
+                yield (0,  "E307 too many blank lines (%d) in a nested "
+                    "scope, expected %d", blank_lines, method_lines)
+        else:
+            yield (0, "E303 too many blank lines (%d), expected %d",
+                blank_lines, top_level_lines)
     elif STARTSWITH_TOP_LEVEL_REGEX.match(logical_line):
         if indent_level:
             if not (blank_before == method_lines or
@@ -380,11 +389,12 @@
                         if nested or ancestor_level == 0:
                             break
                 if nested:
-                    yield 0, "E306 expected %s blank line before a " \
-                        "nested definition, found 0", method_lines
+                    yield (0, "E306 expected %s blank lines before a "
+                        "nested definition, found %d", method_lines,
+                        blank_before)
                 else:
-                    yield (0, "E301 expected %s blank line, found 0",
-                        method_lines)
+                    yield (0, "E301 expected %s blank lines, found %d",
+                        method_lines, blank_before)
         elif blank_before != top_level_lines:
             yield (0, "E302 expected %s blank lines, found %d",
                 top_level_lines, blank_before)

eric ide

mercurial