Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py

changeset 5586
0e5421d679e7
parent 5389
9b1c800daff3
child 5588
6ba512d9f46a
--- 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:

eric ide

mercurial