Added a check for one element tuples.

Mon, 26 Oct 2015 19:14:34 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 26 Oct 2015 19:14:34 +0100
changeset 4507
1a5bc1ac7c2e
parent 4506
57666e501a42
child 4508
a3b38825acf0

Added a check for one element tuples.

Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/CodeStyleChecker/translations.py file | annotate | diff | comparison | revisions
--- a/Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py	Sat Oct 24 20:36:26 2015 +0200
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py	Mon Oct 26 19:14:34 2015 +0100
@@ -24,6 +24,7 @@
         "M121",
         "M131",
         "M801",
+        "M811",
         
         "M901",
     ]
@@ -68,6 +69,7 @@
             (self.__checkBlindExcept, ("M121",)),
             (self.__checkPep3101, ("M131",)),
             (self.__checkPrintStatements, ("M801",)),
+            (self.__checkTuple, ("M811", )),
         ]
         
         self.__defaultArgs = {
@@ -253,3 +255,12 @@
                 getattr(node.func, 'id', None) == 'print') or \
                (hasattr(ast, 'Print') and isinstance(node, ast.Print)):
                 self.__error(node.lineno - 1, node.col_offset, "M801")
+    
+    def __checkTuple(self):
+        """
+        Private method to check for one element tuples.
+        """
+        for node in ast.walk(self.__tree):
+            if isinstance(node, ast.Tuple) and \
+                    len(node.elts) == 1:
+                self.__error(node.lineno - 1, node.col_offset, "M811")
--- a/Plugins/CheckerPlugins/CodeStyleChecker/translations.py	Sat Oct 24 20:36:26 2015 +0200
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/translations.py	Mon Oct 26 19:14:34 2015 +0100
@@ -400,6 +400,9 @@
     "M801": QCoreApplication.translate(
         "MiscellaneousChecker",
         "print statement found"),
+    "M811": QCoreApplication.translate(
+        "MiscellaneousChecker",
+        "one element tuple found"),
     "M901": QCoreApplication.translate(
         "MiscellaneousChecker",
         "{0}: {1}"),

eric ide

mercurial