Added capability to disable code style checks using an eflags: comment like 'eflags: noqa = M601, M702'.

Fri, 30 Oct 2015 18:18:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 30 Oct 2015 18:18:48 +0100
changeset 4514
e410e76d6538
parent 4512
23e8b848efb0
child 4515
d7cebe39ffba

Added capability to disable code style checks using an eflags: comment like 'eflags: noqa = M601, M702'.

Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py file | annotate | diff | comparison | revisions
Utilities/__init__.py file | annotate | diff | comparison | revisions
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Thu Oct 29 19:10:20 2015 +0100
+++ b/Documentation/Help/source.qhp	Fri Oct 30 18:18:48 2015 +0100
@@ -2192,6 +2192,7 @@
       <keyword name="CodeStyleCheckerDialog.__initFuturesList" id="CodeStyleCheckerDialog.__initFuturesList" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html#CodeStyleCheckerDialog.__initFuturesList" />
       <keyword name="CodeStyleCheckerDialog.__itemFixable" id="CodeStyleCheckerDialog.__itemFixable" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html#CodeStyleCheckerDialog.__itemFixable" />
       <keyword name="CodeStyleCheckerDialog.__modifyFixedResultItem" id="CodeStyleCheckerDialog.__modifyFixedResultItem" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html#CodeStyleCheckerDialog.__modifyFixedResultItem" />
+      <keyword name="CodeStyleCheckerDialog.__modifyOptions" id="CodeStyleCheckerDialog.__modifyOptions" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html#CodeStyleCheckerDialog.__modifyOptions" />
       <keyword name="CodeStyleCheckerDialog.__processError" id="CodeStyleCheckerDialog.__processError" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html#CodeStyleCheckerDialog.__processError" />
       <keyword name="CodeStyleCheckerDialog.__processResult" id="CodeStyleCheckerDialog.__processResult" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html#CodeStyleCheckerDialog.__processResult" />
       <keyword name="CodeStyleCheckerDialog.__resetStatistics" id="CodeStyleCheckerDialog.__resetStatistics" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html#CodeStyleCheckerDialog.__resetStatistics" />
--- a/Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html	Thu Oct 29 19:10:20 2015 +0100
+++ b/Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog.html	Fri Oct 30 18:18:48 2015 +0100
@@ -93,6 +93,9 @@
 <td><a href="#CodeStyleCheckerDialog.__modifyFixedResultItem">__modifyFixedResultItem</a></td>
 <td>Private method to modify a result list entry to show its positive fixed state.</td>
 </tr><tr>
+<td><a href="#CodeStyleCheckerDialog.__modifyOptions">__modifyOptions</a></td>
+<td>Private method to modify the options based on eflag: entries.</td>
+</tr><tr>
 <td><a href="#CodeStyleCheckerDialog.__processError">__processError</a></td>
 <td>Private slot to process an error indication from the service.</td>
 </tr><tr>
@@ -338,6 +341,25 @@
 <dd>
 flag indicating a fixed issue (boolean)
 </dd>
+</dl><a NAME="CodeStyleCheckerDialog.__modifyOptions" ID="CodeStyleCheckerDialog.__modifyOptions"></a>
+<h4>CodeStyleCheckerDialog.__modifyOptions</h4>
+<b>__modifyOptions</b>(<i>source</i>)
+<p>
+        Private method to modify the options based on eflag: entries.
+</p><p>
+        This method looks for comment lines like '# eflag: noqa = M601'
+        at the end of the source in order to extend the list of excluded
+        messages for one file only.
+</p><dl>
+<dt><i>source</i></dt>
+<dd>
+source text (list of str or str)
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+list of checker options
+</dd>
 </dl><a NAME="CodeStyleCheckerDialog.__processError" ID="CodeStyleCheckerDialog.__processError"></a>
 <h4>CodeStyleCheckerDialog.__processError</h4>
 <b>__processError</b>(<i>fn, msg</i>)
--- a/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Thu Oct 29 19:10:20 2015 +0100
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Fri Oct 30 18:18:48 2015 +0100
@@ -436,7 +436,29 @@
             else:
                 self.__batch = True
                 self.checkBatch()
+    
+    def __modifyOptions(self, source):
+        """
+        Private method to modify the options based on eflag: entries.
         
+        This method looks for comment lines like '# eflag: noqa = M601'
+        at the end of the source in order to extend the list of excluded
+        messages for one file only.
+        
+        @param source source text (list of str or str)
+        @return list of checker options
+        """
+        options = self.__options[:]
+        flags = Utilities.extractFlags(source)
+        if "noqa" in flags and isinstance(flags["noqa"], str):
+            excludeMessages = \
+                options[0].strip().rstrip(",")
+            if excludeMessages:
+                excludeMessages += ","
+            excludeMessages += flags["noqa"]
+            options[0] = excludeMessages
+        return options
+    
     def check(self, codestring=''):
         """
         Public method to start a style check for one file.
@@ -485,6 +507,8 @@
                 ('-selected', '-default', '-guessed', '-ignore')):
             encoding = encoding.rsplit('-', 1)[0]
         
+        options = self.__modifyOptions(source)
+        
         errors = []
         self.__itms = []
         for error, itm in self.__onlyFixes.pop(self.filename, []):
@@ -492,7 +516,7 @@
             self.__itms.append(itm)
         
         eol = self.__getEol(self.filename)
-        args = self.__options + [
+        args = options + [
             errors, eol, encoding, Preferences.getEditor("CreateBackupFile")
         ]
         self.__finished = False
@@ -532,6 +556,8 @@
                     ('-selected', '-default', '-guessed', '-ignore')):
                 encoding = encoding.rsplit('-', 1)[0]
             
+            options = self.__modifyOptions(source)
+            
             errors = []
             self.__itms = []
             for error, itm in self.__onlyFixes.pop(filename, []):
@@ -539,7 +565,7 @@
                 self.__itms.append(itm)
             
             eol = self.__getEol(filename)
-            args = self.__options + [
+            args = options + [
                 errors, eol, encoding,
                 Preferences.getEditor("CreateBackupFile")
             ]
--- a/Utilities/__init__.py	Thu Oct 29 19:10:20 2015 +0100
+++ b/Utilities/__init__.py	Fri Oct 30 18:18:48 2015 +0100
@@ -632,7 +632,11 @@
             flags[key] = value
         else:
             # treat it as a boolean
-            flags[flag] = True
+            if flag[0] == "-":
+                # false flags start with '-'
+                flags[flag[1:]] = False
+            else:
+                flags[flag] = True
     
     return flags
 

eric ide

mercurial