eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py

changeset 7987
e8eb8370ea94
parent 7923
91e843545d9a
child 7998
cd41c844862f
equal deleted inserted replaced
7986:2971d5d19951 7987:e8eb8370ea94
128 "D130", "D131", "D132", "D133", "D134", 128 "D130", "D131", "D132", "D133", "D134",
129 "D141", "D142", "D143", "D144", "D145", 129 "D141", "D142", "D143", "D144", "D145",
130 130
131 "D203", "D205", "D206", 131 "D203", "D205", "D206",
132 "D221", "D222", 132 "D221", "D222",
133 "D231", "D232", "D234", "D235", "D236", "D237", "D238", "D239", 133 "D231", "D232", "D234r", "D234y", "D235r", "D235y", "D236", "D237",
134 "D238", "D239",
134 "D242", "D243", "D244", "D245", "D246", "D247", 135 "D242", "D243", "D244", "D245", "D246", "D247",
135 "D250", "D251", "D252", "D253", 136 "D250", "D251", "D252", "D253",
136 "D260", "D261", "D262", "D263", 137 "D260", "D261", "D262", "D263",
137 138
138 "D901", 139 "D901",
230 ], 231 ],
231 "defDocstring": [ 232 "defDocstring": [
232 (self.__checkFunctionDocstring, ("D102", "D203")), 233 (self.__checkFunctionDocstring, ("D102", "D203")),
233 (self.__checkImperativeMood, ("D132",)), 234 (self.__checkImperativeMood, ("D132",)),
234 (self.__checkNoSignature, ("D133",)), 235 (self.__checkNoSignature, ("D133",)),
235 (self.__checkEricReturn, ("D234", "D235")), 236 (self.__checkEricReturn, ("D234r", "D235r")),
237 (self.__checkEricYield, ("D234y", "D235y")),
236 (self.__checkEricFunctionArguments, 238 (self.__checkEricFunctionArguments,
237 ("D236", "D237", "D238", "D239")), 239 ("D236", "D237", "D238", "D239")),
238 (self.__checkEricNoBlankBeforeAndAfterClassOrFunction, 240 (self.__checkEricNoBlankBeforeAndAfterClassOrFunction,
239 ("D244", "D245")), 241 ("D244", "D245")),
240 (self.__checkEricException, 242 (self.__checkEricException,
1067 return 1069 return
1068 1070
1069 tokens = list( 1071 tokens = list(
1070 tokenize.generate_tokens(StringIO(context.ssource()).readline)) 1072 tokenize.generate_tokens(StringIO(context.ssource()).readline))
1071 return_ = [tokens[i + 1][0] for i, token in enumerate(tokens) 1073 return_ = [tokens[i + 1][0] for i, token in enumerate(tokens)
1072 if token[1] in ("return", "yield")] 1074 if token[1] == "return"]
1073 if "@return" not in docstringContext.ssource(): 1075 if "@return" not in docstringContext.ssource():
1074 if (set(return_) - 1076 if (set(return_) -
1075 {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} != 1077 {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} !=
1076 set()): 1078 set()):
1077 self.__error(docstringContext.end(), 0, "D234") 1079 self.__error(docstringContext.end(), 0, "D234r")
1078 else: 1080 else:
1079 if (set(return_) - 1081 if (set(return_) -
1080 {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} == 1082 {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} ==
1081 set()): 1083 set()):
1082 self.__error(docstringContext.end(), 0, "D235") 1084 self.__error(docstringContext.end(), 0, "D235r")
1085
1086 def __checkEricYield(self, docstringContext, context):
1087 """
1088 Private method to check, that docstrings contain an @yield line
1089 if they return anything and don't otherwise.
1090
1091 @param docstringContext docstring context (DocStyleContext)
1092 @param context context of the docstring (DocStyleContext)
1093 """
1094 if docstringContext is None:
1095 return
1096
1097 tokens = list(
1098 tokenize.generate_tokens(StringIO(context.ssource()).readline))
1099 yield_ = [tokens[i + 1][0] for i, token in enumerate(tokens)
1100 if token[1] == "yield"]
1101 if "@yield" not in docstringContext.ssource():
1102 if (set(yield_) -
1103 {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} !=
1104 set()):
1105 self.__error(docstringContext.end(), 0, "D234y")
1106 else:
1107 if (set(yield_) -
1108 {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} ==
1109 set()):
1110 self.__error(docstringContext.end(), 0, "D235y")
1083 1111
1084 def __checkEricFunctionArguments(self, docstringContext, context): 1112 def __checkEricFunctionArguments(self, docstringContext, context):
1085 """ 1113 """
1086 Private method to check, that docstrings contain an @param and/or 1114 Private method to check, that docstrings contain an @param and/or
1087 @keyparam line for each argument. 1115 @keyparam line for each argument.

eric ide

mercurial