eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py

changeset 7256
4ef3b78ebb4e
parent 7243
cfeea029d8e1
child 7360
9190402e4505
diff -r d595f6f9cbf8 -r 4ef3b78ebb4e eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py	Sat Sep 21 18:30:02 2019 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py	Sat Sep 21 20:30:56 2019 +0200
@@ -634,11 +634,13 @@
                     while True:
                         start, end = None, None
                         while not (kind == tokenize.NAME and value == 'def'):
-                            kind, value, (line, char), _, _ = \
+                            kind, value, (line, char), _, _ = (
                                 next(tokenGenerator)
+                            )
                         start = line - 1, char
-                        kind, value, (line, char), _, _ = \
+                        kind, value, (line, char), _, _ = (
                             self.__skipIndentedBlock(tokenGenerator)
+                        )
                         end = line - 1, char
                         startLine = classContext.start() + start[0]
                         endLine = classContext.start() + end[0]
@@ -646,11 +648,15 @@
                             self.__source[startLine:endLine],
                             startLine, "def")
                         if startLine > 0:
-                            if self.__source[startLine - 1].strip() == \
-                                    "@staticmethod":
+                            if (
+                                self.__source[startLine - 1].strip() ==
+                                "@staticmethod"
+                            ):
                                 context.setSpecial("staticmethod")
-                            elif self.__source[startLine - 1].strip() == \
-                                    "@classmethod":
+                            elif (
+                                self.__source[startLine - 1].strip() ==
+                                "@classmethod"
+                            ):
                                 context.setSpecial("classmethod")
                         contexts.append(context)
                 except StopIteration:
@@ -703,8 +709,11 @@
                 not docstring.strip('\'"')):
             self.__error(context.start(), 0, "D101")
         
-        if self.__docType == "eric" and \
-           docstring.strip('\'"').strip() == "Module documentation goes here.":
+        if (
+            self.__docType == "eric" and
+            docstring.strip('\'"').strip() ==
+            "Module documentation goes here."
+        ):
             self.__error(docstringContext.end(), 0, "D201")
             return
     
@@ -734,9 +743,11 @@
                 not docstring.strip('\'"')):
             self.__error(context.start(), 0, code)
         
-        if self.__docType == "eric" and \
-           docstring.strip('\'"').strip() == \
-                "Function documentation goes here.":
+        if (
+            self.__docType == "eric" and
+            docstring.strip('\'"').strip() ==
+            "Function documentation goes here."
+        ):
             self.__error(docstringContext.end(), 0, "D202")
             return
     
@@ -767,8 +778,10 @@
             self.__error(context.start(), 0, code)
             return
         
-        if self.__docType == "eric" and \
-           docstring.strip('\'"').strip() == "Class documentation goes here.":
+        if (
+            self.__docType == "eric" and
+            docstring.strip('\'"').strip() == "Class documentation goes here."
+        ):
             self.__error(docstringContext.end(), 0, "D206")
             return
     
@@ -814,8 +827,10 @@
             return
         
         docstring = docstringContext.ssource().strip()
-        if not docstring.startswith('u"""') and \
-                any(ord(char) > 127 for char in docstring):
+        if (
+            not docstring.startswith('u"""') and
+            any(ord(char) > 127 for char in docstring)
+        ):
             self.__error(docstringContext.start(), 0, "D113")
     
     def __checkOneLiner(self, docstringContext, context):
@@ -927,8 +942,10 @@
         
         functionName = context.source()[0].lstrip().split()[1].split("(")[0]
         summary, lineNumber = self.__getSummaryLine(docstringContext)
-        if functionName + "(" in summary.replace(" ", "") and \
-                not functionName + "()" in summary.replace(" ", ""):
+        if (
+            functionName + "(" in summary.replace(" ", "") and
+            not functionName + "()" in summary.replace(" ", "")
+        ):
             # report only, if it is not an abbreviated form (i.e. function() )
             self.__error(docstringContext.start() + lineNumber, 0, "D133")
     
@@ -965,9 +982,11 @@
         
         contextLines = context.source()
         cti = 0
-        while cti < len(contextLines) and \
-                not contextLines[cti].strip().startswith(
-                ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")):
+        while (
+            cti < len(contextLines) and
+            not contextLines[cti].strip().startswith(
+                ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''"))
+        ):
             cti += 1
         if cti == len(contextLines):
             return
@@ -988,9 +1007,11 @@
         
         contextLines = context.source()
         cti = 0
-        while cti < len(contextLines) and \
+        while (
+            cti < len(contextLines) and
             not contextLines[cti].strip().startswith(
-                ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")):
+                ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''"))
+        ):
             cti += 1
         if cti == len(contextLines):
             return
@@ -1001,8 +1022,10 @@
             # it is a multi line docstring
             cti += 1
         
-        while cti < len(contextLines) and \
-                not contextLines[cti].strip().endswith(('"""', "'''")):
+        while (
+            cti < len(contextLines) and
+            not contextLines[cti].strip().endswith(('"""', "'''"))
+        ):
             cti += 1
         end = cti
         if cti >= len(contextLines) - 1:
@@ -1089,8 +1112,11 @@
             if summaryLines[-1].lstrip().startswith("@"):
                 summaryLines.pop(-1)
             summary = " ".join([s.strip() for s in summaryLines if s])
-            if summary and not summary.endswith(".") and \
-                    not summary.split(None, 1)[0].lower() == "constructor":
+            if (
+                summary and
+                not summary.endswith(".") and
+                not summary.split(None, 1)[0].lower() == "constructor"
+            ):
                 self.__error(
                     docstringContext.start() + lineNumber +
                     len(summaryLines) - 1,
@@ -1199,16 +1225,20 @@
             if token[1] == "raise":
                 exceptions.add(tokens[i + 1][0])
                 if tokens[i + 1][0] == tokenize.NAME:
-                    if tokensLen > (i + 2) and \
-                       tokens[i + 2][1] == ".":
+                    if (
+                        tokensLen > (i + 2) and
+                        tokens[i + 2][1] == "."
+                    ):
                         raisedExceptions.add("{0}.{1}".format(
                             tokens[i + 1][1], tokens[i + 3][1]))
                     else:
                         raisedExceptions.add(tokens[i + 1][1])
         
-        if "@exception" not in docstringContext.ssource() and \
-                "@throws" not in docstringContext.ssource() and \
-                "@raise" not in docstringContext.ssource():
+        if (
+            "@exception" not in docstringContext.ssource() and
+            "@throws" not in docstringContext.ssource() and
+            "@raise" not in docstringContext.ssource()
+        ):
             if (exceptions -
                     {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} !=
                     set()):
@@ -1329,9 +1359,11 @@
         contextLines = context.source()
         isClassContext = contextLines[0].lstrip().startswith("class ")
         cti = 0
-        while cti < len(contextLines) and \
+        while (
+            cti < len(contextLines) and
             not contextLines[cti].strip().startswith(
-                ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")):
+                ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''"))
+        ):
             cti += 1
         if cti == len(contextLines):
             return
@@ -1342,8 +1374,10 @@
             # it is a multi line docstring
             cti += 1
         
-        while cti < len(contextLines) and \
-                not contextLines[cti].strip().endswith(('"""', "'''")):
+        while (
+            cti < len(contextLines) and
+            not contextLines[cti].strip().endswith(('"""', "'''"))
+        ):
             cti += 1
         end = cti
         if cti >= len(contextLines) - 1:
@@ -1394,15 +1428,18 @@
         if summary:
             # check, if the first word is 'Constructor', 'Public',
             # 'Protected' or 'Private'
-            functionName, arguments = context.source()[0].lstrip()\
-                .split()[1].split("(", 1)
+            functionName, arguments = (
+                context.source()[0].lstrip().split()[1].split("(", 1)
+            )
             firstWord = summary.strip().split(None, 1)[0].lower()
             if functionName == '__init__':
                 if firstWord != 'constructor':
                     self.__error(docstringContext.start() + lineNumber, 0,
                                  "D232", 'constructor')
-            elif functionName.startswith('__') and \
-                    functionName.endswith('__'):
+            elif (
+                functionName.startswith('__') and
+                functionName.endswith('__')
+            ):
                 if firstWord != 'special':
                     self.__error(docstringContext.start() + lineNumber, 0,
                                  "D232", 'special')
@@ -1416,8 +1453,10 @@
                         if firstWord != 'private':
                             self.__error(docstringContext.start() + lineNumber,
                                          0, "D232", 'private static')
-                    elif functionName.startswith('_') or \
-                            functionName.endswith('Event'):
+                    elif (
+                        functionName.startswith('_') or
+                        functionName.endswith('Event')
+                    ):
                         if firstWord != 'protected':
                             self.__error(docstringContext.start() + lineNumber,
                                          0, "D232", 'protected static')
@@ -1425,8 +1464,10 @@
                         if firstWord != 'public':
                             self.__error(docstringContext.start() + lineNumber,
                                          0, "D232", 'public static')
-            elif arguments.startswith(('cls,', 'cls)')) or \
-                    context.special() == "classmethod":
+            elif (
+                arguments.startswith(('cls,', 'cls)')) or
+                context.special() == "classmethod"
+            ):
                 secondWord = summary.strip().split(None, 2)[1].lower()
                 if firstWord != 'class' and secondWord != 'class':
                     self.__error(docstringContext.start() + lineNumber, 0,
@@ -1436,8 +1477,10 @@
                         if firstWord != 'private':
                             self.__error(docstringContext.start() + lineNumber,
                                          0, "D232", 'private class')
-                    elif functionName.startswith('_') or \
-                            functionName.endswith('Event'):
+                    elif (
+                        functionName.startswith('_') or
+                        functionName.endswith('Event')
+                    ):
                         if firstWord != 'protected':
                             self.__error(docstringContext.start() + lineNumber,
                                          0, "D232", 'protected class')
@@ -1449,8 +1492,10 @@
                 if firstWord != 'private':
                     self.__error(docstringContext.start() + lineNumber, 0,
                                  "D232", 'private')
-            elif functionName.startswith('_') or \
-                    functionName.endswith('Event'):
+            elif (
+                functionName.startswith('_') or
+                functionName.endswith('Event')
+            ):
                 if firstWord != 'protected':
                     self.__error(docstringContext.start() + lineNumber, 0,
                                  "D232", 'protected')

eric ide

mercurial