Plugins/CheckerPlugins/Pep8/Pep8Fixer.py

changeset 2878
61042247f793
parent 2876
bfa39cf40277
child 2879
12e6e199d0cf
diff -r bfa39cf40277 -r 61042247f793 Plugins/CheckerPlugins/Pep8/Pep8Fixer.py
--- a/Plugins/CheckerPlugins/Pep8/Pep8Fixer.py	Sat Aug 31 15:21:28 2013 +0200
+++ b/Plugins/CheckerPlugins/Pep8/Pep8Fixer.py	Sat Aug 31 17:57:30 2013 +0200
@@ -160,6 +160,36 @@
         
         return True
     
+    def __codeMatch(self, code):
+        """
+        Private method to check, if the code should be fixed.
+        
+        @param code to check (string)
+        @return flag indicating it should be fixed (boolean)
+        """
+        def mutualStartswith(a, b):
+            """
+            Local helper method to compare the beginnings of two strings
+            against each other.
+            
+            @return flag indicating that one string starts with the other
+                (boolean)
+            """
+            return b.startswith(a) or a.startswith(b)
+        
+        if self.__noFixCodes:
+            for noFixCode in [c.strip() for c in self.__noFixCodes]:
+                if mutualStartswith(code.lower(), noFixCode.lower()):
+                    return False
+
+        if self.__fixCodes:
+            for fixCode in [c.strip() for c in self.__fixCodes]:
+                if mutualStartswith(code.lower(), fixCode.lower()):
+                    return True
+            return False
+
+        return True
+    
     def fixIssue(self, line, pos, message):
         """
         Public method to fix the fixable issues.
@@ -173,8 +203,7 @@
         code = message.split(None, 1)[0].strip()
         
         if line <= len(self.__source) and \
-           code not in self.__noFixCodes and \
-           (code in self.__fixCodes or len(self.__fixCodes) == 0) and \
+           self.__codeMatch(code) and \
            code in self.__fixes:
             res = self.__fixes[code](code, line, pos)
             if res[0]:

eric ide

mercurial