112 "D141", "D142", "D143", "D144", "D145", |
112 "D141", "D142", "D143", "D144", "D145", |
113 |
113 |
114 "D203", "D205", |
114 "D203", "D205", |
115 "D221", |
115 "D221", |
116 "D231", "D234", "D235", "D236", "D237", "D238", |
116 "D231", "D234", "D235", "D236", "D237", "D238", |
117 "D242", "D243", "D244", "D245", |
117 "D242", "D243", "D244", "D245", "D246", "D247", |
118 ] |
118 ] |
119 |
119 |
120 Messages = { |
120 Messages = { |
121 "D101": QT_TRANSLATE_NOOP( |
121 "D101": QT_TRANSLATE_NOOP( |
122 "Pep257Checker", "module is missing a docstring"), |
122 "Pep257Checker", "module is missing a docstring"), |
194 "Pep257Checker", "class docstring is preceded by a blank line"), |
194 "Pep257Checker", "class docstring is preceded by a blank line"), |
195 "D243": QT_TRANSLATE_NOOP( |
195 "D243": QT_TRANSLATE_NOOP( |
196 "Pep257Checker", "class docstring is followed by a blank line"), |
196 "Pep257Checker", "class docstring is followed by a blank line"), |
197 "D244": QT_TRANSLATE_NOOP( |
197 "D244": QT_TRANSLATE_NOOP( |
198 "Pep257Checker", |
198 "Pep257Checker", |
|
199 "function/method docstring is preceded by a blank line"), |
|
200 "D245": QT_TRANSLATE_NOOP( |
|
201 "Pep257Checker", |
|
202 "function/method docstring is followed by a blank line"), |
|
203 "D246": QT_TRANSLATE_NOOP( |
|
204 "Pep257Checker", |
199 "docstring summary is not followed by a blank line"), |
205 "docstring summary is not followed by a blank line"), |
200 "D245": QT_TRANSLATE_NOOP( |
206 "D247": QT_TRANSLATE_NOOP( |
201 "Pep257Checker", |
207 "Pep257Checker", |
202 "last paragraph of docstring is followed by a blank line"), |
208 "last paragraph of docstring is followed by a blank line"), |
203 } |
209 } |
204 |
210 |
205 def __init__(self, source, filename, select, ignore, expected, repeat, |
211 def __init__(self, source, filename, select, ignore, expected, repeat, |
298 (self.__checkImperativeMood, ("D132",)), |
304 (self.__checkImperativeMood, ("D132",)), |
299 (self.__checkNoSignature, ("D133",)), |
305 (self.__checkNoSignature, ("D133",)), |
300 (self.__checkEricReturn, ("D234",)), |
306 (self.__checkEricReturn, ("D234",)), |
301 (self.__checkEricFunctionArguments, |
307 (self.__checkEricFunctionArguments, |
302 ("D235", "D236", "D237", "D238")), |
308 ("D235", "D236", "D237", "D238")), |
303 (self.__checkNoBlankLineBefore, ("D141",)), |
309 ## (self.__checkNoBlankLineBefore, ("D141",)), |
|
310 (self.__checkEricNoBlankBeforeAndAfterClassOrFunction, |
|
311 ("D244", "D245")), |
304 ], |
312 ], |
305 "docstring": [ |
313 "docstring": [ |
306 (self.__checkTripleDoubleQuotes, ("D111",)), |
314 (self.__checkTripleDoubleQuotes, ("D111",)), |
307 (self.__checkBackslashes, ("D112",)), |
315 (self.__checkBackslashes, ("D112",)), |
308 (self.__checkUnicode, ("D113",)), |
316 (self.__checkUnicode, ("D113",)), |
309 (self.__checkEricOneLiner, ("D221",)), |
317 (self.__checkEricOneLiner, ("D221",)), |
310 (self.__checkIndent, ("D122",)), |
318 (self.__checkIndent, ("D122",)), |
311 (self.__checkEricEndsWithPeriod, ("D231",)), |
319 (self.__checkEricEndsWithPeriod, ("D231",)), |
312 (self.__checkEricBlankAfterSummary, ("D244",)), |
320 (self.__checkEricBlankAfterSummary, ("D246",)), |
313 (self.__checkEricNBlankAfterLastParagraph, ("D245",)), |
321 (self.__checkEricNBlankAfterLastParagraph, ("D247",)), |
314 ], |
322 ], |
315 } |
323 } |
316 |
324 |
317 self.__checkers = {} |
325 self.__checkers = {} |
318 for key, checkers in checkersWithCodes.items(): |
326 for key, checkers in checkersWithCodes.items(): |
1173 return |
1181 return |
1174 |
1182 |
1175 summaryLines, lineNumber = self.__getSummaryLines(docstringContext) |
1183 summaryLines, lineNumber = self.__getSummaryLines(docstringContext) |
1176 if len(docstrings) > lineNumber + len(summaryLines) - 1: |
1184 if len(docstrings) > lineNumber + len(summaryLines) - 1: |
1177 if docstrings[lineNumber + len(summaryLines)].strip(): |
1185 if docstrings[lineNumber + len(summaryLines)].strip(): |
1178 self.__error(docstringContext.start() + lineNumber, 0, "D244") |
1186 self.__error(docstringContext.start() + lineNumber, 0, "D246") |
1179 |
1187 |
1180 def __checkEricNoBlankBeforeAndAfterClass(self, docstringContext, context): |
1188 def __checkEricNoBlankBeforeAndAfterClassOrFunction( |
1181 """ |
1189 self, docstringContext, context): |
1182 Private method to check, that class docstrings have no blank line |
1190 """ |
1183 around them. |
1191 Private method to check, that class and function/method docstrings |
|
1192 have no blank line around them. |
1184 |
1193 |
1185 @param docstringContext docstring context (Pep257Context) |
1194 @param docstringContext docstring context (Pep257Context) |
1186 @param context context of the docstring (Pep257Context) |
1195 @param context context of the docstring (Pep257Context) |
1187 """ |
1196 """ |
1188 if docstringContext is None: |
1197 if docstringContext is None: |
1189 return |
1198 return |
1190 |
1199 |
1191 contextLines = context.source() |
1200 contextLines = context.source() |
|
1201 isClassContext = contextLines[0].lstrip().startswith("class ") |
1192 cti = 0 |
1202 cti = 0 |
1193 while cti < len(contextLines) and \ |
1203 while cti < len(contextLines) and \ |
1194 not contextLines[cti].strip().startswith( |
1204 not contextLines[cti].strip().startswith( |
1195 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")): |
1205 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")): |
1196 cti += 1 |
1206 cti += 1 |
1208 cti += 1 |
1218 cti += 1 |
1209 end = cti |
1219 end = cti |
1210 if cti == len(contextLines): |
1220 if cti == len(contextLines): |
1211 return |
1221 return |
1212 |
1222 |
1213 if not contextLines[start - 1].strip(): |
1223 if isClassContext: |
1214 self.__error(docstringContext.start(), 0, "D242") |
1224 if not contextLines[start - 1].strip(): |
1215 if not contextLines[end + 1].strip(): |
1225 self.__error(docstringContext.start(), 0, "D242") |
1216 self.__error(docstringContext.end(), 0, "D243") |
1226 if not contextLines[end + 1].strip(): |
|
1227 self.__error(docstringContext.end(), 0, "D243") |
|
1228 else: |
|
1229 if not contextLines[start - 1].strip(): |
|
1230 self.__error(docstringContext.start(), 0, "D244") |
|
1231 if not contextLines[end + 1].strip(): |
|
1232 self.__error(docstringContext.end(), 0, "D245") |
1217 |
1233 |
1218 def __checkEricNBlankAfterLastParagraph(self, docstringContext, context): |
1234 def __checkEricNBlankAfterLastParagraph(self, docstringContext, context): |
1219 """ |
1235 """ |
1220 Private method to check, that the last paragraph of docstrings is |
1236 Private method to check, that the last paragraph of docstrings is |
1221 not followed by a blank line. |
1237 not followed by a blank line. |