110 "D141", "D142", "D143", "D144", "D145", |
110 "D141", "D142", "D143", "D144", "D145", |
111 |
111 |
112 "D203", "D205", |
112 "D203", "D205", |
113 "D221", |
113 "D221", |
114 "D231", "D234", "D235", "D236", "D237", "D238", |
114 "D231", "D234", "D235", "D236", "D237", "D238", |
115 "D242", "D243", "D244", "D245", |
115 "D242", "D243", "D244", "D245", "D246", "D247", |
116 ] |
116 ] |
117 |
117 |
118 def __init__(self, source, filename, select, ignore, expected, repeat, |
118 def __init__(self, source, filename, select, ignore, expected, repeat, |
119 maxLineLength=79, docType="pep257"): |
119 maxLineLength=79, docType="pep257"): |
120 """ |
120 """ |
211 (self.__checkImperativeMood, ("D132",)), |
211 (self.__checkImperativeMood, ("D132",)), |
212 (self.__checkNoSignature, ("D133",)), |
212 (self.__checkNoSignature, ("D133",)), |
213 (self.__checkEricReturn, ("D234",)), |
213 (self.__checkEricReturn, ("D234",)), |
214 (self.__checkEricFunctionArguments, |
214 (self.__checkEricFunctionArguments, |
215 ("D235", "D236", "D237", "D238")), |
215 ("D235", "D236", "D237", "D238")), |
216 (self.__checkNoBlankLineBefore, ("D141",)), |
216 (self.__checkEricNoBlankBeforeAndAfterClassOrFunction, |
|
217 ("D244", "D245")), |
217 ], |
218 ], |
218 "docstring": [ |
219 "docstring": [ |
219 (self.__checkTripleDoubleQuotes, ("D111",)), |
220 (self.__checkTripleDoubleQuotes, ("D111",)), |
220 (self.__checkBackslashes, ("D112",)), |
221 (self.__checkBackslashes, ("D112",)), |
221 (self.__checkUnicode, ("D113",)), |
222 (self.__checkUnicode, ("D113",)), |
222 (self.__checkEricOneLiner, ("D221",)), |
223 (self.__checkEricOneLiner, ("D221",)), |
223 (self.__checkIndent, ("D122",)), |
224 (self.__checkIndent, ("D122",)), |
224 (self.__checkEricEndsWithPeriod, ("D231",)), |
225 (self.__checkEricEndsWithPeriod, ("D231",)), |
225 (self.__checkEricBlankAfterSummary, ("D244",)), |
226 (self.__checkEricBlankAfterSummary, ("D246",)), |
226 (self.__checkEricNBlankAfterLastParagraph, ("D245",)), |
227 (self.__checkEricNBlankAfterLastParagraph, ("D247",)), |
227 ], |
228 ], |
228 } |
229 } |
229 |
230 |
230 self.__checkers = {} |
231 self.__checkers = {} |
231 for key, checkers in checkersWithCodes.items(): |
232 for key, checkers in checkersWithCodes.items(): |
1065 return |
1066 return |
1066 |
1067 |
1067 summaryLines, lineNumber = self.__getSummaryLines(docstringContext) |
1068 summaryLines, lineNumber = self.__getSummaryLines(docstringContext) |
1068 if len(docstrings) > lineNumber + len(summaryLines) - 1: |
1069 if len(docstrings) > lineNumber + len(summaryLines) - 1: |
1069 if docstrings[lineNumber + len(summaryLines)].strip(): |
1070 if docstrings[lineNumber + len(summaryLines)].strip(): |
1070 self.__error(docstringContext.start() + lineNumber, 0, "D244") |
1071 self.__error(docstringContext.start() + lineNumber, 0, "D246") |
1071 |
1072 |
1072 def __checkEricNoBlankBeforeAndAfterClass(self, docstringContext, context): |
1073 def __checkEricNoBlankBeforeAndAfterClassOrFunction( |
1073 """ |
1074 self, docstringContext, context): |
1074 Private method to check, that class docstrings have no blank line |
1075 """ |
1075 around them. |
1076 Private method to check, that class and function/method docstrings |
|
1077 have no blank line around them. |
1076 |
1078 |
1077 @param docstringContext docstring context (Pep257Context) |
1079 @param docstringContext docstring context (Pep257Context) |
1078 @param context context of the docstring (Pep257Context) |
1080 @param context context of the docstring (Pep257Context) |
1079 """ |
1081 """ |
1080 if docstringContext is None: |
1082 if docstringContext is None: |
1081 return |
1083 return |
1082 |
1084 |
1083 contextLines = context.source() |
1085 contextLines = context.source() |
|
1086 isClassContext = contextLines[0].lstrip().startswith("class ") |
1084 cti = 0 |
1087 cti = 0 |
1085 while cti < len(contextLines) and \ |
1088 while cti < len(contextLines) and \ |
1086 not contextLines[cti].strip().startswith( |
1089 not contextLines[cti].strip().startswith( |
1087 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")): |
1090 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")): |
1088 cti += 1 |
1091 cti += 1 |
1100 cti += 1 |
1103 cti += 1 |
1101 end = cti |
1104 end = cti |
1102 if cti == len(contextLines): |
1105 if cti == len(contextLines): |
1103 return |
1106 return |
1104 |
1107 |
1105 if not contextLines[start - 1].strip(): |
1108 if isClassContext: |
1106 self.__error(docstringContext.start(), 0, "D242") |
1109 if not contextLines[start - 1].strip(): |
1107 if not contextLines[end + 1].strip(): |
1110 self.__error(docstringContext.start(), 0, "D242") |
1108 self.__error(docstringContext.end(), 0, "D243") |
1111 if not contextLines[end + 1].strip(): |
|
1112 self.__error(docstringContext.end(), 0, "D243") |
|
1113 else: |
|
1114 if not contextLines[start - 1].strip(): |
|
1115 self.__error(docstringContext.start(), 0, "D244") |
|
1116 if not contextLines[end + 1].strip(): |
|
1117 self.__error(docstringContext.end(), 0, "D245") |
1109 |
1118 |
1110 def __checkEricNBlankAfterLastParagraph(self, docstringContext, context): |
1119 def __checkEricNBlankAfterLastParagraph(self, docstringContext, context): |
1111 """ |
1120 """ |
1112 Private method to check, that the last paragraph of docstrings is |
1121 Private method to check, that the last paragraph of docstrings is |
1113 not followed by a blank line. |
1122 not followed by a blank line. |