Some refinements of the last changeset.

Fri, 09 Mar 2018 18:54:34 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 09 Mar 2018 18:54:34 +0100
changeset 6178
905ea208884a
parent 6177
af76e795c4ce
child 6179
8d74886f2107

Some refinements of the last changeset.

Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py file | annotate | diff | comparison | revisions
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Thu Mar 08 19:03:19 2018 +0100
+++ b/Documentation/Help/source.qhp	Fri Mar 09 18:54:34 2018 +0100
@@ -11018,6 +11018,7 @@
       <keyword name="MiscellaneousChecker.__checkPep3101" id="MiscellaneousChecker.__checkPep3101" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html#MiscellaneousChecker.__checkPep3101" />
       <keyword name="MiscellaneousChecker.__checkPrintStatements" id="MiscellaneousChecker.__checkPrintStatements" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html#MiscellaneousChecker.__checkPrintStatements" />
       <keyword name="MiscellaneousChecker.__checkTuple" id="MiscellaneousChecker.__checkTuple" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html#MiscellaneousChecker.__checkTuple" />
+      <keyword name="MiscellaneousChecker.__dictShouldBeChecked" id="MiscellaneousChecker.__dictShouldBeChecked" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html#MiscellaneousChecker.__dictShouldBeChecked" />
       <keyword name="MiscellaneousChecker.__error" id="MiscellaneousChecker.__error" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html#MiscellaneousChecker.__error" />
       <keyword name="MiscellaneousChecker.__getCoding" id="MiscellaneousChecker.__getCoding" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html#MiscellaneousChecker.__getCoding" />
       <keyword name="MiscellaneousChecker.__getFields" id="MiscellaneousChecker.__getFields" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html#MiscellaneousChecker.__getFields" />
--- a/Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html	Thu Mar 08 19:03:19 2018 +0100
+++ b/Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker.html	Fri Mar 09 18:54:34 2018 +0100
@@ -96,6 +96,9 @@
 <td><a href="#MiscellaneousChecker.__checkTuple">__checkTuple</a></td>
 <td>Private method to check for one element tuples.</td>
 </tr><tr>
+<td><a href="#MiscellaneousChecker.__dictShouldBeChecked">__dictShouldBeChecked</a></td>
+<td>Private function to test, if the node should be checked.</td>
+</tr><tr>
 <td><a href="#MiscellaneousChecker.__error">__error</a></td>
 <td>Private method to record an issue.</td>
 </tr><tr>
@@ -203,7 +206,27 @@
 <b>__checkTuple</b>(<i></i>)
 <p>
         Private method to check for one element tuples.
-</p><a NAME="MiscellaneousChecker.__error" ID="MiscellaneousChecker.__error"></a>
+</p><a NAME="MiscellaneousChecker.__dictShouldBeChecked" ID="MiscellaneousChecker.__dictShouldBeChecked"></a>
+<h4>MiscellaneousChecker.__dictShouldBeChecked</h4>
+<b>__dictShouldBeChecked</b>(<i>node</i>)
+<p>
+        Private function to test, if the node should be checked.
+</p><dl>
+<dt><i>node</i></dt>
+<dd>
+reference to the AST node
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating to check the node
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
+</dl><a NAME="MiscellaneousChecker.__error" ID="MiscellaneousChecker.__error"></a>
 <h4>MiscellaneousChecker.__error</h4>
 <b>__error</b>(<i>lineNumber, offset, code, *args</i>)
 <p>
--- a/Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py	Thu Mar 08 19:03:19 2018 +0100
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py	Fri Mar 09 18:54:34 2018 +0100
@@ -616,13 +616,30 @@
                         self.__error(default.lineno - 1, default.col_offset,
                                      errorCode, typeName)
     
+    def __dictShouldBeChecked(self, node):
+        """
+        Private function to test, if the node should be checked.
+        
+        @param node reference to the AST node
+        @return flag indicating to check the node
+        @rtype bool
+        """
+        if not all(isinstance(key, ast.Str) for key in node.keys):
+            return False
+        
+        if "__IGNORE_WARNING__" in self.__source[node.lineno - 1] or \
+           "__IGNORE_WARNING_M201__" in self.__source[node.lineno - 1]:
+            return False
+        
+        lineNumbers = [key.lineno for key in node.keys]
+        return len(lineNumbers) == len(set(lineNumbers))
+    
     def __checkDictWithSortedKeys(self):
         """
         Private method to check, if dictionary keys appear in sorted order.
         """
         for node in ast.walk(self.__tree):
-            if isinstance(node, ast.Dict) and \
-               all(isinstance(key, ast.Str) for key in node.keys):
+            if isinstance(node, ast.Dict) and self.__dictShouldBeChecked(node):
                 for key1, key2 in zip(node.keys, node.keys[1:]):
                     if key2.s < key1.s:
                         self.__error(key2.lineno - 1, key2.col_offset,

eric ide

mercurial