diff -r 866adc8c315b -r 0acf98cd089a eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py --- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py Sun Jan 17 13:53:08 2021 +0100 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py Mon Feb 01 10:38:16 2021 +0100 @@ -128,9 +128,10 @@ "D130", "D131", "D132", "D133", "D134", "D141", "D142", "D143", "D144", "D145", - "D203", "D205", "D206", + "D201", "D202.1", "D202.2", "D203", "D205", "D206", "D221", "D222", - "D231", "D232", "D234", "D235", "D236", "D237", "D238", "D239", + "D231", "D232", "D234r", "D234y", "D235r", "D235y", "D236", "D237", + "D238", "D239", "D242", "D243", "D244", "D245", "D246", "D247", "D250", "D251", "D252", "D253", "D260", "D261", "D262", "D263", @@ -150,8 +151,8 @@ @param expected list of expected codes (list of string) @param repeat flag indicating to report each occurrence of a code (boolean) - @keyparam maxLineLength allowed line length (integer) - @keyparam docType type of the documentation strings + @param maxLineLength allowed line length (integer) + @param docType type of the documentation strings (string, one of 'eric' or 'pep257') """ self.__select = tuple(select) @@ -215,7 +216,7 @@ elif self.__docType == "eric": checkersWithCodes = { "moduleDocstring": [ - (self.__checkModulesDocstrings, ("D101",)), + (self.__checkModulesDocstrings, ("D101", "D201")), ], "functionDocstring": [ ], @@ -229,10 +230,12 @@ (self.__checkEricSummary, ("D232")), ], "defDocstring": [ - (self.__checkFunctionDocstring, ("D102", "D203")), + (self.__checkFunctionDocstring, + ("D102", "D202.1", "D202.2", "D203")), (self.__checkImperativeMood, ("D132",)), (self.__checkNoSignature, ("D133",)), - (self.__checkEricReturn, ("D234", "D235")), + (self.__checkEricReturn, ("D234r", "D235r")), + (self.__checkEricYield, ("D234y", "D235y")), (self.__checkEricFunctionArguments, ("D236", "D237", "D238", "D239")), (self.__checkEricNoBlankBeforeAndAfterClassOrFunction, @@ -439,18 +442,12 @@ arguments = [] arguments.extend([arg.arg for arg in node.args.args]) if node.args.vararg is not None: - if sys.version_info < (3, 4, 0): - arguments.append(node.args.vararg) - else: - arguments.append(node.args.vararg.arg) + arguments.append(node.args.vararg.arg) kwarguments = [] kwarguments.extend([arg.arg for arg in node.args.kwonlyargs]) if node.args.kwarg is not None: - if sys.version_info < (3, 4, 0): - kwarguments.append(node.args.kwarg) - else: - kwarguments.append(node.args.kwarg.arg) + kwarguments.append(node.args.kwarg.arg) return arguments, kwarguments ################################################################## @@ -699,13 +696,20 @@ not docstring.strip('\'"')): self.__error(context.start(), 0, code) - if ( - self.__docType == "eric" and - docstring.strip('\'"').strip() == - "Function documentation goes here." - ): - self.__error(docstringContext.end(), 0, "D202") - return + if self.__docType == "eric": + if ( + docstring.strip('\'"').strip() == + "Function documentation goes here." + ): + self.__error(docstringContext.end(), 0, "D202.1") + return + + if ( + "DESCRIPTION" in docstring or + "TYPE" in docstring + ): + self.__error(docstringContext.end(), 0, "D202.2") + return def __checkClassDocstring(self, docstringContext, context): """ @@ -1075,17 +1079,43 @@ tokens = list( tokenize.generate_tokens(StringIO(context.ssource()).readline)) return_ = [tokens[i + 1][0] for i, token in enumerate(tokens) - if token[1] in ("return", "yield")] + if token[1] == "return"] if "@return" not in docstringContext.ssource(): if (set(return_) - {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} != set()): - self.__error(docstringContext.end(), 0, "D234") + self.__error(docstringContext.end(), 0, "D234r") else: if (set(return_) - {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} == set()): - self.__error(docstringContext.end(), 0, "D235") + self.__error(docstringContext.end(), 0, "D235r") + + def __checkEricYield(self, docstringContext, context): + """ + Private method to check, that docstrings contain an @yield line + if they return anything and don't otherwise. + + @param docstringContext docstring context (DocStyleContext) + @param context context of the docstring (DocStyleContext) + """ + if docstringContext is None: + return + + tokens = list( + tokenize.generate_tokens(StringIO(context.ssource()).readline)) + yield_ = [tokens[i + 1][0] for i, token in enumerate(tokens) + if token[1] == "yield"] + if "@yield" not in docstringContext.ssource(): + if (set(yield_) - + {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} != + set()): + self.__error(docstringContext.end(), 0, "D234y") + else: + if (set(yield_) - + {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} == + set()): + self.__error(docstringContext.end(), 0, "D235y") def __checkEricFunctionArguments(self, docstringContext, context): """