Added capability to place line flags (e.g. __IGNORE...) on the line following the one to be ignored.

Tue, 07 Mar 2017 18:46:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 07 Mar 2017 18:46:09 +0100
changeset 5586
0e5421d679e7
parent 5585
dab20c39f08c
child 5587
ea526b78ee6c

Added capability to place line flags (e.g. __IGNORE...) on the line following the one to be ignored.

Debugger/DebugUI.py file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleChecker.html file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheck.html file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Utilities.__init__.html file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py file | annotate | diff | comparison | revisions
Utilities/__init__.py file | annotate | diff | comparison | revisions
changelog file | annotate | diff | comparison | revisions
--- a/Debugger/DebugUI.py	Tue Mar 07 18:42:41 2017 +0100
+++ b/Debugger/DebugUI.py	Tue Mar 07 18:46:09 2017 +0100
@@ -1119,10 +1119,16 @@
                     file, line = stackTrace[0][:2]
                     source, encoding = Utilities.readEncodedFile(file)
                     source = source.splitlines(True)
-                    if len(source) >= line and \
-                       "__IGNORE_EXCEPTION__" in Utilities.extractLineFlags(
-                            source[line - 1]):
-                        res = E5MessageBox.No
+                    if len(source) >= line:
+                        lineFlags = Utilities.extractLineFlags(
+                            source[line - 1].strip())
+                        try:
+                            lineFlags += Utilities.extractLineFlags(
+                                source[line].strip(), flagsLine=True)
+                        except IndexError:
+                            pass
+                        if "__IGNORE_EXCEPTION__" in lineFlags:
+                            res = E5MessageBox.No
                 except (UnicodeError, IOError):
                     pass
                 if res != E5MessageBox.No:
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleChecker.html	Tue Mar 07 18:42:41 2017 +0100
+++ b/Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleChecker.html	Tue Mar 07 18:46:09 2017 +0100
@@ -229,6 +229,9 @@
 </dd><dt><i>endComment=</i></dt>
 <dd>
 string identifying the end of a comment (string)
+</dd><dt><i>flagsLine=</i></dt>
+<dd>
+flag indicating to check for a flags only line (bool)
 </dd>
 </dl><dl>
 <dt>Returns:</dt>
--- a/Documentation/Source/eric6.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheck.html	Tue Mar 07 18:42:41 2017 +0100
+++ b/Documentation/Source/eric6.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheck.html	Tue Mar 07 18:46:09 2017 +0100
@@ -108,6 +108,9 @@
 </dd><dt><i>endComment=</i></dt>
 <dd>
 string identifying the end of a comment (string)
+</dd><dt><i>flagsLine=</i></dt>
+<dd>
+flag indicating to check for a flags only line (bool)
 </dd>
 </dl><dl>
 <dt>Returns:</dt>
--- a/Documentation/Source/eric6.Utilities.__init__.html	Tue Mar 07 18:42:41 2017 +0100
+++ b/Documentation/Source/eric6.Utilities.__init__.html	Tue Mar 07 18:46:09 2017 +0100
@@ -727,6 +727,9 @@
 </dd><dt><i>endComment=</i></dt>
 <dd>
 string identifying the end of a comment (string)
+</dd><dt><i>flagsLine=</i></dt>
+<dd>
+flag indicating to check for a flags only line (bool)
 </dd>
 </dl><dl>
 <dt>Returns:</dt>
--- a/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py	Tue Mar 07 18:42:41 2017 +0100
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py	Tue Mar 07 18:46:09 2017 +0100
@@ -74,7 +74,7 @@
         return code
 
 
-def extractLineFlags(line, startComment="#", endComment=""):
+def extractLineFlags(line, startComment="#", endComment="", flagsLine=False):
     """
     Function to extract flags starting and ending with '__' from a line
     comment.
@@ -82,17 +82,22 @@
     @param line line to extract flags from (string)
     @keyparam startComment string identifying the start of the comment (string)
     @keyparam endComment string identifying the end of a comment (string)
+    @keyparam flagsLine flag indicating to check for a flags only line (bool)
     @return list containing the extracted flags (list of strings)
     """
     flags = []
     
-    pos = line.rfind(startComment)
-    if pos >= 0:
-        comment = line[pos + len(startComment):].strip()
-        if endComment:
-            comment = comment.replace("endComment", "")
-        flags = [f.strip() for f in comment.split()
-                 if (f.startswith("__") and f.endswith("__"))]
+    if not flagsLine or (
+       flagsLine and line.strip().startswith(startComment)):
+        pos = line.rfind(startComment)
+        if pos >= 0:
+            comment = line[pos + len(startComment):].strip()
+            if endComment:
+                endPos = line.rfind(endComment)
+                if endPos >= 0:
+                    comment = comment[:endPos]
+            flags = [f.strip() for f in comment.split()
+                     if (f.startswith("__") and f.endswith("__"))]
     return flags
 
 
@@ -274,6 +279,11 @@
             if source:
                 code = text[0]
                 lineFlags = extractLineFlags(source[lineno - 1].strip())
+                try:
+                    lineFlags += extractLineFlags(source[lineno].strip(),
+                                                  flagsLine=True)
+                except IndexError:
+                    pass
                 if "__IGNORE_WARNING__" not in lineFlags and \
                         "__IGNORE_WARNING_{0}__".format(code) not in lineFlags:
                     if fixer:
--- a/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py	Tue Mar 07 18:42:41 2017 +0100
+++ b/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py	Tue Mar 07 18:46:09 2017 +0100
@@ -65,7 +65,7 @@
     return codestring
 
 
-def extractLineFlags(line, startComment="#", endComment=""):
+def extractLineFlags(line, startComment="#", endComment="", flagsLine=False):
     """
     Function to extract flags starting and ending with '__' from a line
     comment.
@@ -73,17 +73,22 @@
     @param line line to extract flags from (string)
     @keyparam startComment string identifying the start of the comment (string)
     @keyparam endComment string identifying the end of a comment (string)
+    @keyparam flagsLine flag indicating to check for a flags only line (bool)
     @return list containing the extracted flags (list of strings)
     """
     flags = []
     
-    pos = line.rfind(startComment)
-    if pos >= 0:
-        comment = line[pos + len(startComment):].strip()
-        if endComment:
-            comment = comment.replace("endComment", "")
-        flags = [f.strip() for f in comment.split()
-                 if (f.startswith("__") and f.endswith("__"))]
+    if not flagsLine or (
+       flagsLine and line.strip().startswith(startComment)):
+        pos = line.rfind(startComment)
+        if pos >= 0:
+            comment = line[pos + len(startComment):].strip()
+            if endComment:
+                endPos = line.rfind(endComment)
+                if endPos >= 0:
+                    comment = comment[:endPos]
+            flags = [f.strip() for f in comment.split()
+                     if (f.startswith("__") and f.endswith("__"))]
     return flags
 
 
@@ -282,8 +287,13 @@
                 continue
             
             _fn, lineno, col, message, msg_args = warning.getMessageData()
-            if "__IGNORE_WARNING__" not in extractLineFlags(
-                    lines[lineno - 1].strip()):
+            lineFlags = extractLineFlags(lines[lineno - 1].strip())
+            try:
+                lineFlags += extractLineFlags(lines[lineno].strip(),
+                                              flagsLine=True)
+            except IndexError:
+                pass
+            if "__IGNORE_WARNING__" not in lineFlags:
                 results.append((_fn, lineno, col, "", message, msg_args))
     except SyntaxError as err:
         if err.text.strip():
--- a/Utilities/__init__.py	Tue Mar 07 18:42:41 2017 +0100
+++ b/Utilities/__init__.py	Tue Mar 07 18:46:09 2017 +0100
@@ -656,7 +656,7 @@
     return extractFlags(source)
 
 
-def extractLineFlags(line, startComment="#", endComment=""):
+def extractLineFlags(line, startComment="#", endComment="", flagsLine=False):
     """
     Function to extract flags starting and ending with '__' from a line
     comment.
@@ -664,17 +664,22 @@
     @param line line to extract flags from (string)
     @keyparam startComment string identifying the start of the comment (string)
     @keyparam endComment string identifying the end of a comment (string)
+    @keyparam flagsLine flag indicating to check for a flags only line (bool)
     @return list containing the extracted flags (list of strings)
     """
     flags = []
     
-    pos = line.rfind(startComment)
-    if pos >= 0:
-        comment = line[pos + len(startComment):].strip()
-        if endComment:
-            comment = comment.replace("endComment", "")
-        flags = [f.strip() for f in comment.split()
-                 if (f.startswith("__") and f.endswith("__"))]
+    if not flagsLine or (
+       flagsLine and line.strip().startswith(startComment)):
+        pos = line.rfind(startComment)
+        if pos >= 0:
+            comment = line[pos + len(startComment):].strip()
+            if endComment:
+                endPos = line.rfind(endComment)
+                if endPos >= 0:
+                    comment = comment[:endPos]
+            flags = [f.strip() for f in comment.split()
+                     if (f.startswith("__") and f.endswith("__"))]
     return flags
 
 
--- a/changelog	Tue Mar 07 18:42:41 2017 +0100
+++ b/changelog	Tue Mar 07 18:46:09 2017 +0100
@@ -4,7 +4,9 @@
 - bug fixes
 - Checkers
   -- added checks for shadowed Python builtins and unneccessary comprehensions
-     and generators
+     and generators to the code style checker
+  -- added capability to place line flags (e.g. __IGNORE...) on the line
+     following the one to be ignored
 
 Version 17.03:
 - bug fixes

eric ide

mercurial